web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

retrieveMultipleRecords (Client API reference)

(0) ShareShare
ReportReport
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
            }
        );
    }
}
I have the same question (0)
  • Suggested answer
    Amit Katariya007 Profile Picture
    10,409 Super User 2025 Season 2 on at

    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

  • Maurice M Profile Picture
    10 on at

    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
    10,409 Super User 2025 Season 2 on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans