Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

retrieveMultipleRecords (Client API reference)

Posted on by 10

I am very new to Dynamics CRM. My goal is to get the value of an OptionSet field on ABC table and set the same OptionSet field in a different table with the same value. The script is set for onChange on table ABC. The initial error was a MaxPage error. Now when I check the debugger, I see that the API call gets completely skipped. Thanks in advance for your help.

function updateFunction(executionContext) {
    var formContext = executionContext.getFormContext()
    var abcVariable= formContext.getAttribute("fieldABCTable").getValue();
   var recordId = formContext.data.entity.getId();

    if (abcVariable!== null) {
        recordId = recordId.replace(/[{}]/g, "");
        Xrm.WebApi.retrieveMultipleRecords(Xrm.WebApi.retrieveMultipleRecords("entitys", recordId, "?$select=fieldOnOtherTable").then(
            function success(result) {
                for (var i = 0; i < result.entities.length; i++) {
                    console.log(result.entities[i]);
                    formContext.getAttribute(result.entities[i]).setValue(abcVariable)
                }
            },
            function (error) {
                console.log(error.message);
                // handle error conditions
            }
        );
    }
}
  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 5,769 Super User on at
    RE: retrieveMultipleRecords (Client API reference)

    No worries. You are already on right path, so it will be needed some changes as per your requirements that is it.

    Let me know if more information needed.

    Thank you,

    Amit Katariya

  • Maurice M Profile Picture
    Maurice M 10 on at
    RE: retrieveMultipleRecords (Client API reference)

    Hi Amit,

    Thanks for the assistance. I used parts of your script to complete the task. I needed to do the retrieval first to check if the field on the ABC table matched the field on the additional table first. Then I made the update if there wasn't a match.

    Best,

  • Suggested answer
    Amit Katariya007 Profile Picture
    Amit Katariya007 5,769 Super User on at
    RE: retrieveMultipleRecords (Client API reference)

    Hello Maurice,

    You already have the GUID of a record where you want to update the option set. so why you are retrieving it?

    Just use below code which will help you to update the option set and remove the retrieve code from your code.

    function updateFunction(executionContext) 
    {
        var formContext = executionContext.getFormContext()
        var recordId = formContext.data.entity.getId();
        
        var record = {};
        record.fieldlogicalname = formContext.getAttribute("fieldABCTable").getValue(); // Replace fieldlogicalname with option set logical name
        if (formContext.getAttribute("fieldABCTable").getValue() !== null) 
        {
            recordId = recordId.replace(/[{}]/g, "");
            Xrm.WebApi.online.updateRecord("mention entity Name", recordId "", record).then(
                function success(result) 
                {
                    var updatedId = result.id;
                    console.log(updatedId);
                },
                function(error) 
                {
                    console.log(error.message);
                }
            );
        }
    }

    Thank you,

    Amit Katariya

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans