Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Get Account id and to update the custom entity field in CRM 2013

Posted on by 40

Hi,

I am using Dynamics CRM 2013.
In Account entity, I have a custom field new_subject.
I need to get this value and update in the custom entity Subject field new_StudentSubject by using Jscript.
Whenever I will select the Account lookup on the Subject entity.

Both are text fields as a datatype.
Account to Subject we had relationship 1: N.

Thanks,

*This post is locked for comments

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    Kalpavruksh D365 CoE 2,545 on at
    RE: Get Account id and to update the custom entity field in CRM 2013
    Hi,
    You will have to get guid of the selected Account and then get the field value from an Account to populate it in the custom entity.
    To fetch the values from an Account, please refer to the this link which describes oData fetch queries to get the data from parent record: http://mehmetgunen.com/retrieve-data-using-odata-queries-with-javascript-in-crm-2013/
  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Get Account id and to update the custom entity field in CRM 2013

    Hi Alita,

    Please refer below code:

    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/accounts(D4C36C65-507C-E911-A994-00224800CEEF)?$select=new_subject", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function() {
    if (this.readyState === 4) {
    req.onreadystatechange = null;
    if (this.status === 200) {
    var result = JSON.parse(this.response);
    var SubjectValue = result["new_subject"];
    Xrm.Page.getAttribute("new_StudentSubject").setValue(SubjectValue);
    } else {
    Xrm.Utility.alertDialog(this.statusText);
    }
    }
    };
    req.send();

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans