Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Auto populate value from Account to Opportunity

(0) ShareShare
ReportReport
Posted on by 310

Hello, I am trying to populate the value of State from Accounts to Opportunity.

function oppStateOnChange()

{
if(Xrm.Page.getAttribute("customerid").getValue()!=null)

//read

var opportunity = Xrm.Page.getAttribute("customerid").getValue()[0].id;

var opportunityId = opportunity.substring(1, 37);

opportunityId = opportunityId.replace('{', '').replace('}', '');
var req = new XMLHttpRequest();

req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + opportunityId + ")?$select=address1_stateorprovince", 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 oppnumber1 = result["address1_stateorprovince"];

Xrm.Page.getAttribute("new_opportunitystate").setValue(oppnumber1);

} else {

Xrm.Utility.alertDialog(this.statusText);

}

}

};

req.send();

}

new_opportunitystate is a option set. Is is possible to populate a value in the Option set field or I will have to create a new Text field?

Thank you.

*This post is locked for comments

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,205 on at
    RE: Auto populate value from Account to Opportunity

    Hi Huzefa,

    Pleases check below link, for copying the field value from parent entity to child having 1:N relationship

    itsolutions.bdo.ca/.../using-field-mapping-in-microsoft-dynamics-crm-to-copy-data-between-associated-records

    Best Regards,

    Shahbaaz

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans