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

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Problem with nested Xrm.WebApi.retrieveRecord in UCI

(0) ShareShare
ReportReport
Posted on by 75

I have some JavaScript that does a setFormEntityName, works fine in classic interface but not working in the Unified Interface.

Looks like this is down to having a nested Xrm.WebApi.retrieveRecord. We are retrieving a contact record, getting accountid from that and when retrieving an account record and using the account name in setFormEntityName

The second nested Xrm.WebApi.retrieveRecord just doesn't work in the UCI, but is fine in classic interface, does anyone know if tis is a known issue/

Thanks

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Problem with nested Xrm.WebApi.retrieveRecord in UCI

    Hello,

    Can you please provide code you use?

  • mmcmahon Profile Picture
    75 on at
    RE: Problem with nested Xrm.WebApi.retrieveRecord in UCI

    Thanks for the reply Andrew -

    function Lead_OnChange_Contact(executionContext) {

       var formContext = executionContext.getFormContext != null ? executionContext.getFormContext() : executionContext;

       var creation = 1;

       if (formContext.ui.getFormType() == creation && formContext.getAttribute('cw_employeereferral').getValue() == true) {

           var contactid = formContext.getAttribute("parentcontactid").getValue()[0].id;

           Xrm.WebApi.retrieveRecord("contact", contactid, "?$select=_parentcustomerid_value, firstname, lastname, fullname")

               .then(function (contact) {

                   var accountid = contact["_parentcustomerid_value"];

                   formContext.getAttribute('firstname').setValue(contact["firstname"]);

                   formContext.getAttribute('lastname').setValue(contact["lastname"]);

                   formContext.getAttribute('fullname').setValue(contact["fullname"]);

                   Xrm.WebApi.retrieveRecord("account", accountid, "?$select=name")

                       .then(function (account) {

                           formContext.ui.setFormEntityName("Employee referral from " + Xrm.Utility.getGlobalContext().userSettings.userName + " to " + account.name);

                       })

               })

       }

    }

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Problem with nested Xrm.WebApi.retrieveRecord in UCI

    Hello,

    I don't see any issue in the code. One thing that I wanted to notice is that you have no need to do the second retrieve because name of the company is already in the response and you can get it using following line:

    var accountName = contact["_parentcustomerid_value@OData.Community.Display.V1.FormattedValue"];

  • mmcmahon Profile Picture
    75 on at
    RE: Problem with nested Xrm.WebApi.retrieveRecord in UCI

    Many thanks, no idea why the nested call isn't working in the UCI but you're right, we don't need it anyway. Got it working now without it :)

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 85 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 57 Most Valuable Professional

#3
Satyam Prakash Profile Picture

Satyam Prakash 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans