CRUD operations using executeMultiple in Dynamics 365 WebApi

Just another day at office and yet another challenge. Looked a simple one at the beginning. Basically here is the requirement

“Multiple create and update operations needs to be performed using Dynamics 365 Web API through client side.”

Off-course we can use the Xrm.WebApi.createRecord or Xrm.WebApi.updateRecord but in that case for as many records, those many server side calls need to be made from the client side.

But Microsoft has covered our back right! We have the executeMultiple method. So what’s the fuss about?

Well although we have the method but how to make it work. So basically the executeMultiple will accept an array of request object. And to create the request object, we can easily fall back to the documentation of execute method.

Unfortunately the document lacks in showing how to perform a CRUD operation request object. And that’s the fuss is all about. Things like this believe me, would take you days to resolve.

Well not to worry. If you think that this is going to take away your night’s sleep, I have done that for you. So let’s jump straight to the action here. Check for the parts highlighted in yellow. There in lies all the tricks!

And here is how to create request object for CREATE. Below is the code to create a request object for Account create.

var cAccount = {};
            cAccount["name"] = "CRUD Test";

// put your remaining fields to create the account object.

            var request = {};
            request.getMetadata = function () {
                return {
                     boundParameter: undefined,
                    operationType: 2,
                    operationName: "Create",
                     parameterTypes: {

                    }
                 };
            };

           request.etn = "account";
            request.payload = cAccount;

Below is the code to UPDATE an existing account.

var uAccount = {};
            uAccount["name"] = "CRUD Test – Update";

            var request2 = {};
            request2.getMetadata = function () {
                return {
                     boundParameter: undefined,
                    operationType: 2,
                    operationName: "Update",
                    parameterTypes: {

                    }
                };
            };

            request2.etn = "account";
            request2.payload = uAccount;

request2.id = “<put your account id here>”;

And finally the execute multiple code.

Xrm.WebApi.executeMultiple([request, request2]).then(
           function (results) {
               debugger;

               // parse your results here
            },
           function (error) {
           });

Hope this will help many and save your time!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Multiselect picklist for Dynamics 365 (http://www.xrmforyou.com/multi-select-picklist.html)

Advertisements

Add metadata to your SharePoint files, Drag & drop, Multiple Document Location, multiple documents at one go and many more–the new version of Sharepoint metadata manager & attachment uploader

Pleasure to announce that we are releasing a new version of most successful utility – “SharePoint metadata manager and attachment uploader”.

What does this new release contain?

1. Support for multiple document location feature for a record.

Our previous versions of the tool relied on the OOB CRM-SharePoint integration feature and hence the user did not have an option to upload a document for a record in a folder of his choice. Going forward, users will have the option to create a document location on the fly and update documents for the record.

2. Alternate method of authentication with the Sharepoint APP model instead of using a username and password.

The tool now supports an alternate method of authentication using the Sharepoint add-in. In this way, the tool no longer need to depend on a Sharepoint username and password.

3. It’s faster now!

Our team continuously works on this and now we have made some platform changes to make our tool faster.

Apart from all this it already carries the wonderful functionality it had in it’s previous versions.

  • Ability to add/ edit metadata in Sharepoint through CRM
  • Ability to upload more up-to five documents at one go with metadata.
  • Drag and drop.
  • Control behavior in compliance with the CRM security
  • Automatically moving attachments from notes to Sharepoint

For trial write to us at – info@xrmforyou.com

Documentation and video link – http://www.xrmforyou.com/sharepoint-integrator.html

image

image

image

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

Multiselect picklist for Dynamics 365 (http://www.xrmforyou.com/multi-select-picklist.html)