LINQ: GroupBy, Sum and EntityCollection

Just resharing a sample code that could be used for group by and sum operation on EntityCollection.

Suppose below is the output that we want

Continue reading “LINQ: GroupBy, Sum and EntityCollection”

Linq and Parallel.ForEach loop

If requests are internal then Linq query will perform better over Parallel.ForEach and for external request Parallel.ForEach will perform better than Linq request.

Parller Foreach is faster than traditional For or ForEach loop

private List GetOrganizationRequests(List incidents)
         {
             var orgRequests = new List();
         Parallel.ForEach(incidents.Where(x => x.Contains("statuscode") && x.Contains("qi.queueitemid") && x.Contains("tm.queueid")), incident =>
         {
             orgRequests.Add(new AddToQueueRequest
             {
                 SourceQueueId = ((EntityReference)((AliasedValue)incident["qi.queueid"]).Value).Id,
                 Target = new EntityReference("incident", incident.Id),
                 DestinationQueueId = ((EntityReference)((AliasedValue)incident["tm.queueid"]).Value).Id
             });
         });
         return orgRequests;
     }

Linq query for same request

private List GetOrganizationRequests(List incidents) =>
             incidents.Where(x => x.Contains("statuscode") && x.Contains("qi.queueitemid") && x.Contains("tm.queueid"))
             .Select(z => new AddToQueueRequest()
             {
                 SourceQueueId = ((EntityReference)((AliasedValue)z["qi.queueid"]).Value).Id,
                 Target = new EntityReference("incident", z.Id),
                 DestinationQueueId = ((EntityReference)((AliasedValue)z["tm.queueid"]).Value).Id
             }).Cast().ToList();

hope its helps !!

Activate-Deactivate Plugins/Process with code

while deploying our customisation to target environment many times we need disable/deactivate plugins and or process. Manually, its straight forward but what about when you are working with DevOps or you cannot touch target environment. In such environment, we need to handle it with code. So for that here are the steps …

Continue reading “Activate-Deactivate Plugins/Process with code”

System jobs in Dynamics

For DevOps, we have to handle each and everything from code behind and in automated way. Thus, wrote code to create manage System jobs to delete records every night in Dynamics. Here are the main points from my understanding ..

The BulkDeleteRequest message will create a bulk delete job that will be automatically executed on a specified interval for a specified set of data.  The job will be executed by the CRM Asynchronous service.

Continue reading “System jobs in Dynamics”

workflow execution from Plugin

Here is quick sample code for workflow execution from Plugin …

Execute workflow …

Continue reading “workflow execution from Plugin”

Query hierarchical data

Retiring hierarchical data is easy, we don’t need to iterate by for/while loop. just use ‘Above’ or ‘Under’ keywords, then it will serve you all parents or all child available.

in regular query, just ‘ConditionOperator.Above’ to get all parents.

in regular query, just ‘ConditionOperator.Under’ to get all child.

How to create this type of structure

Continue reading “Query hierarchical data”

LinkEntity issue with ‘Partyid’

Today, I was working with LinkEntity for ‘PartyId’, So I want all appointment where specific account or contact is in the required field and is connected to a specific entity.

Thus, I created 3 appointments on the entity and wrote following query… Continue reading “LinkEntity issue with ‘Partyid’”

Linq Entity with filter

data retrival

Many times we need to joins with filters in one entity or both of them. Here is the simple sample …

Continue reading “Linq Entity with filter”

Error: AliasedValue – Key not found

Key not Found

Error: Key not found in Link Entity QueryExpression (Ref above image). Continue reading “Error: AliasedValue – Key not found”