Sunday, June 17, 2018

Using SDK.Rest.retrieveRecord function

There are number of occasions where we have to access the fields of a lookup on a form and populate fields on the child form with the values that are coming from the parent lookup form fields. We use the sdk.rest.retreiverecord function to achieve this task with javascript.

For us to use this method the following javascript file has to be referenced before.


Then only we can call the function.

example of a function.

 var accountLookUp = Xrm.Page.getAttribute("msdyn_account").getValue();

        if (accountLookUp != null) {

            var Id = accountLookUp[0].id.replace("{", "").replace("}", "");

            SDK.REST.retrieveRecord(Id, "Account", "isv_ABC, isv_Country, isv_County", null, function (accountEntity) {

                

            }, function (error) {
                alert(error);
                alert(error.message);
            });
        }
        else {
      
        }

A lot of issues are arising with the fields to be retrieved. The field name is case sensitive and if it's not properly given then an error will appear stating "Error: Error : 400: : Type 'Microsoft.Crm.Sdk.Data.Services.Account' does not have a property named 'isv_abc'."

We can find this easily by doing the following. 

Paste the url of an account record in the browser and it will bring all the properties of the entity. You can find the field name from this list and refer it correctly. This has saved me a lot of time.

URL: https://crmresearch9.api.crm6.dynamics.com/XRMServices/2011/OrganizationData.svc/AccountSet(guid'ab132b6f-1101-e811-a832-000d3ab4f534')


The output will be like below. You will be able to pick the correct field name for the operation.



No comments:

Post a Comment

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...