Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Problem with nested Xrm.WebApi.retrieveRecord in UCI

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

  • mmcmahon Profile Picture
    mmcmahon 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 :)

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 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
    mmcmahon 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);

                       })

               })

       }

    }

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

    Hello,

    Can you please provide code you use?

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

Product updates

Dynamics 365 release plans