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

Announcements

No record found.

News and Announcements icon
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

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Can you please provide code you use?

  • mmcmahon Profile Picture
    75 on at

    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

    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

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
11manish Profile Picture

11manish 74 Super User 2026 Season 2

#2
Travis South Profile Picture

Travis South 35

#3
Martin Dráb Profile Picture

Martin Dráb 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans