Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
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 8,454 Super User 2024 Season 1 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 8,454 Super User 2024 Season 1 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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans