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

Announcements

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 Moderator 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 Moderator 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 50 Super User 2026 Season 1

#2
Eugen Podkorytov Profile Picture

Eugen Podkorytov 49

#3
Fiona_Tiernan Profile Picture

Fiona_Tiernan 22 Moderator

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans