Hello,
We are using CRM Online version 9.1
Have implemented this code to populate value from Accounts to Invoice (Contact lookup) on onChange of Customer field.
function test()
{
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/v9.1/accounts(" + opportunityId + ")?$select=_new_invoicetocontactname_value", 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.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var _new_invoicetocontactname_value = result["_new_invoicetocontactname_value"];
var _new_invoicetocontactname_value_formatted = result["_new_invoicetocontactname_value@OData.Community.Display.V1.FormattedValue"];
var _new_invoicetocontactname_value_lookuplogicalname = result["_new_invoicetocontactname_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id =_new_invoicetocontactname_value; // GUID of the lookup id
lookupValue[0].name = _new_invoicetocontactname_value_formatted; // Name of the lookup
lookupValue[0].entityType = "contact"; //Entity Type of the lookup entity
Xrm.Page.getAttribute("new_invoicetocontactname").setValue(lookupValue);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
After value is populated, it shows no name in the lookup and shows correct value when the record is saved.
I have already asked about this here https://community.dynamics.com/crm/f/117/p/350287/938135#938135 but haven't got the solution yet.
Any help would be appreciated.
Thanx.
*This post is locked for comments
I have the same question (0)