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

Need to populate Customer System User fields based on the Customer system user field of a lookup

(0) ShareShare
ReportReport
Posted on by 20

I am trying to update some fields on a customer entity form with the data gathered from the account lookup on the form.

Now i need to get the system user values of the 2 customer field on the account table (cr787_Partner and cr787_Manager) and use those values to populate a Job_Partner field and a Job_Manager field (both custom) when the account field changes.

Now here is what i have so far in jscript

function setPartnersandManagers() {
var account = Xrm.Page.getAttribute("cr787_accountcode").getValue()
if (account != null){
var accountId = Xrm.Page.getAttribute("cr787_accountcode").getValue()[0].id;
alert(accountId);

Xrm.WebApi.retrieveRecord("account", accountId, "?$select=name,revenue,cr787_Partner,cr787_Manager,ownerid").then(
function success(result) {
alert("Retrieved values: Name: " + result.name + ", Revenue: " + result.revenue);
var partner = result.cr787_Partner;
var name = partner.Name;
alert(name);
// perform operations on record retrieval
},
function (error) {
alert(error.message);
// handle error conditions
}
);
}
}

I can get the retrieveRecord to pull back a record but it appears that the cr787_Partner and Manager fields return undefined when i try to display them in an alert. Now i figure that is because they are lookups themselves.

I can't for the life of me figure out how to get these values and set the values of the two fields on the form.

Any help greatly accepted 

Thanks in advance

Matt

I have the same question (0)
  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: Need to populate Customer System User fields based on the Customer system user field of a lookup

    Hello,

    Try to use dataverse rest builder tool to generate your code.

    carldesouza.com/.../

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Need to populate Customer System User fields based on the Customer system user field of a lookup

    Hi Frostie8467,

    You should use the logical name of your field, not the schema name. You could fine it here:

    pastedimage1658195392369v1.png

     So please change your code like this to have a try:

    function setPartnersandManagers() {
    var account = Xrm.Page.getAttribute("cr787_accountcode").getValue()
    if (account != null){
    var accountId = Xrm.Page.getAttribute("cr787_accountcode").getValue()[0].id;
    alert(accountId);

    Xrm.WebApi.retrieveRecord("account", accountId, "?$select=name,revenue,cr787_partner,cr787_manager,ownerid").then(
    function success(result) {
    alert("Retrieved values: Name: " + result.name + ", Revenue: " + result.revenue);
    var partner = result.cr787_partner;
    var name = partner.Name;
    alert(name);
    // perform operations on record retrieval
    },
    function (error) {
    alert(error.message);
    // handle error conditions
    }
    );
    }
    }

  • Frostie8467 Profile Picture
    20 on at
    RE: Need to populate Customer System User fields based on the Customer system user field of a lookup

    thank you Bipin thjat worked amazingly.

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... 76 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 55 Most Valuable Professional

#3
Anthony Blake Profile Picture

Anthony Blake 43 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans