Greg Thomas' Post

Joining Queries in Dynamics

I recently finished a project that required some pretty complicated querying between entities to get at the data.

What I found is that I was making too many calls to get linked data between EntityReferences in my code to the server.

To improve the performance of these calls I made use of the Addlink functionality on the QueryExpression.

Whereas before I was making two calls to get at my entity data, now I was only going to make one.

My initial query looked like this

QueryExpression query = new QueryExpression(); query.EntityName = "ENTITY"; query.Criteria.AddCondition(new ConditionExpression("ATTR_FILTER1", ConditionOperator.Equal, APPID)); query.Criteria.AddCondition(new ConditionExpression("ATTR_FILTER2", ConditionOperator.Equal, SearchId)); query.ColumnSet = new ColumnSet(new string[] { ENT_LOOKUP_ID, ENT_LOOKUP_ID2 }); 

var plink = query.AddLink("ENTITY2", ENT_LOOKUP_ID2D , ENT_LOOKUP_ID2 , JoinOperator.Inner); plink.EntityAlias = "PH"; plink.Columns.AddColumns("ATTR_FILTER4", "ATTR_FILTER5");

 

When executed as a normal query, this in turn

Read More


Comments are King

///

That is all it takes to explain what you are doing, why you are doing it, how you are doing it and where you will do it.

It’s not rocket science, it’s not complicated, it doesn’t add hours to your coding effort and in some cases it has the potential to be an added dose of humour to your fellow colleagues as you work through a particularly stressful problem.

Comments were put to me in the best way possible years ago…

Imagine the person behind you is a Crazed Serial Killer and your lack of comments will be the tipping point for them.

Comment your code not only for your team, but for yourself, so you remember why you wrote it, what stress you were under and why it shouldn’t be refactored.

Dynamics Plugins and

Read More


Using the Bulk API to Create Records

I wanted to build a data populator for Dynamics that created a bunch of custom records and did some associations between them.

(The reasoning is so I could be sure I was always validating the same thing).

To do this, I wanted to use the Bulk API.  The Bulk API has a limit of 1000 requests per message so in addition to bulk loading my requests, I needed to ensure that multiple requests could be queued up and handled by the server.

Here is some of the sample code I wrote for this interaction.

public void BulkDispatchCreateRequests<T>(List<T> requests)
 {
 int MaxBatchSize = 999;
 bool CreateBatchRequest = true;

ExecuteMultipleRequest requestWithResults = null;

for (int i = 0; i < requests.Count(); i++)
 {
 if (CreateBatchRequest)
 {
 requestWithResults = new ExecuteMultipleRequest()
 {
 // Assign settings that define execution behavior:															

Read More


Dynamics SDK Paging Records

I never thought I’d have a case when I’d need to work with over 5,000 records from the Dynamics SDK.

The scenario here is that I was trying to reproduce some production issues and validate out some code changes with a higher threshold of objects.  However, as I started testing, I noticed I wasn’t bringing back everything and had hit the that magical 5,000 limit.

Without wanting to change it, I modified by query to support the retrieval of 5,000+ items that would return to my service to be worked on.

bool KeepSearching = true;
 EntityCollection results = null;
 Dictionary <Guid, Entity> Accessors = new Dictionary<Guid, Entity>();

QueryExpression query = new QueryExpression();
 query.EntityName = "contact";
 query.Criteria.AddCondition(new ConditionExpression("contactid", ConditionOperator.Equal, ContactId));
 query.ColumnSet = new ColumnSet(new string[] { "contactid", "fullname"});
 query.PageInfo = new PagingInfo();
  query.PageInfo.PageNumber =															

Read More


Retrieving Configuration Values from the USD

In the USD you can create Options that you can use within your Actions/Events/etc in the Unified Service Desk Configuration.

You can also access these values from within your own control via C# relatively easily.

Capture

To access the value within my USD Custom Hosted Control via C# all that is needed is the following code.

GetConfigurationValue("FoodforThought");

And now I can use this value within the USD without having to create my own configuration files et al in C#.

Read More