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