Optimize Delete operation – Dataverse / Dynamics 365

Recently we had to delete records for one of our entities, and we tried out different combinations of batch sizes and the number of threads with 25000 records as a sample to find the optimum setting.

Below is our sample SSIS Package (uses KingswaySoft Dynamics 365 Tool Kit), it retrieves 25000 record’s GUID (Contact table / entity) and then distributes it equally among 3 different CRM Destination Component running under different users (CRM Connection Managers).

How to – improve data migration performance – SSIS & Azure Data Factory (Dataverse / Dynamics 365)

Below is our Premium Derived Column where we have added a new column with expression IncrementValue()

In Conditional Split component, we are then using this new column added to distrubute the output across three CRM Destination Component, each using a different CRM Connection Managers running under different application users.

We first started with 10 batch size and 20 thread followed by different combinations after that à

Below were our findings ->

Records Count Batch Size Thread Parallel Users Elapsed Time
25000 10 20 3 00:15:58.578
25000 10 15 3 00:14:43.734
25000 10 10 3 00:16:06.438
25000 10 5 3 00:23:52.094
25000 10 15 2 00:18.55.012
25000 10 15 1 00:39:15.828
25000 20 30 1 00:39:12.781

As we can see the Batch size 10 and thread around 15 gave us the best performance. However, evert environment / conditions will would be different so we should try out different combinations before finalizing.

SSIS and Microsoft Dynamics 365

Hope it helps..


Sample code (C#) for Multi-Table Lookup / Polymorphic Lookup attribute in Dataverse / Dynamics 365

For creating multi-table lookup we already have an XrmToolBox plugin Polymorphic Lookup Creator which we should be using ideally, but in case somebody wants to try it out, the below shared sample code can be referred.

Below is our custom table named mycustomtable to which we’d add a multi-table lookup which references case, contact and account entity.

We need to call CreatePolymorphicLookupAttribute Action, which expects 3 parameters

Below is the sample code to create the polymorphic lookup.

string ConnectionString = "AuthType = OAuth; " +
                  "AppId=51f81489-12ee-4a9e-aaae-a2591f45987d; " +
                  "Username=user@domain.onmicrosoft.com; " +
                  "Password=pwd; " +
                  "RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;" +
                  "Url = https://orgname.crm4.dynamics.com/;";

 CrmServiceClient svc = new CrmServiceClient(ConnectionString);

            if (svc.IsReady)
                // Create PolymorphicLookupAttribute 
                // with mycustomtable custom entity / table
                // referencing case, contact and account entity
                var varOrgRequest = new OrganizationRequest();

                // specify the request name
                varOrgRequest.RequestName = "CreatePolymorphicLookupAttribute";

                // specify lookup attribute details
                varOrgRequest.Parameters["Lookup"] = new LookupAttributeMetadata()
                    SchemaName = "crf82_mypolymorphiclookup",
                    DisplayName = new Label("My Polymorphic Lookup", 1033)

                // referencing entity is our custom entity named my custom table
                // referenced entity is incident
                var oneToManyRelation1 = new OneToManyRelationshipMetadata();
                oneToManyRelation1.ReferencingEntity = "crf82_mycustomtable";
                oneToManyRelation1.ReferencedEntity = "incident";
                oneToManyRelation1.SchemaName = "crf82_mycustomtable_crf82_incident";

                // referencing entity is our custom entity named my custom table
                // referenced entity is contact
                var oneToManyRelation2 = new OneToManyRelationshipMetadata();
                oneToManyRelation2.ReferencingEntity = "crf82_mycustomtable";
                oneToManyRelation2.ReferencedEntity = "contact";
                oneToManyRelation2.SchemaName = "crf82_mycustomtable_crf82_contact";

                // referencing entity is our custom entity named my custom table
                // referenced entity is account
                var oneToManyRelation3 = new OneToManyRelationshipMetadata();
                oneToManyRelation3.ReferencingEntity = "crf82_mycustomtable";
                oneToManyRelation3.ReferencedEntity = "account";
                oneToManyRelation3.SchemaName = "crf82_mycustomtable_crf82_account";

                // populate OneToManyRelationships parameter of CreatePolymorphicLookupAttribute request
                varOrgRequest.Parameters["OneToManyRelationships"] = new OneToManyRelationshipMetadata[]
                    oneToManyRelation1, oneToManyRelation2, oneToManyRelation3

                // specify the existing solution name 
                varOrgRequest.Parameters["SolutionUniqueName"] = "MySolution";

                var response = svc.Execute(varOrgRequest);

The lookup à

Sample code to add a new relationship to an existing lookup.

                var createOneToManyRelationshipRequest = new CreateOneToManyRequest();

                // referencing entity is our custom entity named mycustomtable
                // referenced entity is contact - add the entity to be added
                var oneToManyRelationAdd = new OneToManyRelationshipMetadata();
                oneToManyRelationAdd.ReferencingEntity = "crf82_mycustomtable";
                oneToManyRelationAdd.ReferencedEntity = "contact";
                oneToManyRelationAdd.SchemaName = "crf82_mycustomtable_crf82_contact";

                createOneToManyRelationshipRequest.OneToManyRelationship = oneToManyRelationAdd;

                // specify lookup attribute details to which new relationship is to be added
                createOneToManyRelationshipRequest.Parameters["Lookup"] = new LookupAttributeMetadata()
                    SchemaName = "crf82_mypolymorphiclookup",
                    DisplayName = new Label("My Polymorphic Lookup", 1033)

                var createOneToManyRelationshipResponse = svc.Execute(createOneToManyRelationshipRequest);

Sample code to remove relationship from an existing lookup.

 var deleteRelationShip = new DeleteRelationshipRequest();
                // specify schema name of the relationship 
                deleteRelationShip.Name = "crf82_mycustomtable_crf82_contact1";

Sample code to delete the lookup

  // User delete attribute request 
                DeleteAttributeRequest varDelRequest = new DeleteAttributeRequest();

                // specify the entity name
                varDelRequest.EntityLogicalName = "crf82_mycustomtable";

                // specify the schema name of the entity
                varDelRequest.LogicalName = "crf82_mymultitablelookup";

Get all the details here –


Hope it helps..


Sample AppId / ClientId and RedirectUri for quick prototyping (Dataverse / Dynamics 365)

At times we want to quickly try out few things (PoC) by writing a console application or running an SSIS package etc., there we can use the sample ClientId and RedirectUri provided by Microsoft, instead of registering the application in Azure AD / creating Application User 

  • Sample AppId or ClientId = 51f81489-12ee-4a9e-aaae-a2591f45987d
  • Sample RedirectUri = app://58145B91-0C36-4500-8554-080854F2AC97


Connection String within a console app à

CDS /CRM Connection Manager of KingswaySoft ->

or use Interactive Login –  https://nishantrana.me/2021/07/01/interactive-login-option-in-cds-crm-connection-manager-in-kingswaysoft-dynamics-365-integration-toolkit/

Also check out -Sample Code (Dynamics 365 Web API) https://nishantrana.me/2021/01/06/sample-code-dynamics-365-web-api-organization-service/

Hope it helps..

 private void Form1_Load(object sender, EventArgs e)

           string ConnectionString = "AuthType = OAuth; " +
           "Username =  [username].onmicrosoft.com; " +
           "Password = [password]; " +
           "Url = https://[org].crm.dynamics.com/;" +
           "AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;" +
           "RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;" +

            CrmServiceClient svc = new CrmServiceClient(ConnectionString);

            if (svc.IsReady)
                 // do the needful


How to – use HTTP Action to call DataVerse / Dynamics 365 Web API in Power Automate

Let us take a simple example, to see the steps involved.

Here we will be manually triggering a flow, getting the token, and calling the WhoAmI request in Microsoft Dataverse / Dynamics 365.

This is how our final Flow looks like.

Inside the first HTTP action, we are calling OAuth 2.0 token endpoint v1. We have MyCrmApp registered in Azure AD and have generated the client secret for it.

Also we have created an Application User using the above application details and have given the appropriate security role.

Below is how our HTTP request looks like.















Next, we have added the Compose action to get the token from the output of the HTTP request.


Inputs (Expression) = outputs(‘HTTP’).body.access_token

Next, we have added the HTTP action again to calls the WhoAmI request using the above token.










Bearer [Output of the previous step]

On triggering our Flow succeeds as shown below.

The output of the first HTTP request.

Compose step has the access token

And the final step has the result of the HTTP Get request to WhoAmI

The helpful post –



Hope it helps..

Check other posts on Power Automate


Can we update ‘SYSTEM’ user in Dynamics 365 / Dataverse?

We recently were asked to check the possibility of updating the SYSTEM user specifically the primary email field of it.


Usually, we use SYSTEM user to specify the plugin’s execution context for business requirements that needs elevation of privileges.

And also we can neither update it from the user interface nor it is recommended to update the SYSTEM user.

If we try to update the user through code, we’d get the below error message

Error updating Users – No modifications to the ‘SYSTEM’ or ‘INTEGRATION’ user are permitted. [See the Execution Plan tab for details of where this error occurred]

Hope it helps..



Update Personal Options / Personalization Settings using UpdateUserSettingsSystemUser Request – Dynamics 365

Recently we had a requirement to update the “Negative Currency Format” – Regional Options for all the users.

We could not find this option in our favorite plugin – User Settings Utility.

So to programmatically update it we use the below code.

Or using our most favorite plugin – SQL 4 CDS

Updating it to the required format – 5

The Result –

Get more details here-


Hope it helps..

C# Code –

  CrmServiceClient svc = new CrmServiceClient(ConnectionString);
            if (svc.IsReady)
                var reqUpdateUserSettings = new UpdateUserSettingsSystemUserRequest();

                // GUID of the System User
                reqUpdateUserSettings.UserId = new Guid("18392d47-9dc0-eb11-8235-00224808ff23");

                // reference the usersettings Entity
                reqUpdateUserSettings.Settings = new Entity("usersettings");

                // update the negativecurrencyformatcode to appropriate integer value
                reqUpdateUserSettings.Settings.Attributes["negativecurrencyformatcode"] = 5;

                var response = (UpdateUserSettingsSystemUserResponse)


update usersettings 
set negativecurrencyformatcode = 5
where systemuserid = '18392d47-9dc0-eb11-8235-00224808ff23'