Yes, I want to add that field within the header section of the case form.
Below is the code which i used and i am able to get the value but no able to setValue.
So, Is there any need to make relationship first?
If yes then suggest me.
function getValues()
{
var contactId;
var res;
var lookupItem = Xrm.Page.getAttribute("customerid").getValue();
if (lookupItem != null)
{
contactId = lookupItem[0].id;
// Added new line
res = contactId.replace("{", "").replace("}", "");
}
else
{
return;
}
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts("+res+")?$select=address1_city,new_orgcode,new_orglocationcode,new_teamflags", false);
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 city = result["address1_city"];
var orgcode = result["new_orgcode"];
var locationcode = result["new_orglocationcode"];
var teamflags = result["new_teamflags"];
Xrm.Page.getAttribute("new_address1_city").setValue(city);
Xrm.Page.getAttribute("new_orgcode").setValue(orgcode);
Xrm.Page.getAttribute("new_orglocationcode").setValue(locationcode);
Xrm.Page.getAttribute("new_teamflags").setValue(teamflags);
}
}
};
req.send();
}