// JavaScript source code
function abc(executionContext)
{
var formContext = executionContext.getFormContext();
var new_dogfood;
var lookup = new Array();
lookup = formContext.getAttribute("Cat_Food").getValue();
if (lookup != null)
{
var name = lookup[0].name;
var id = lookup[0].id;
var entityType = lookup[0].entityType;
}
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/Dog(id)?$select=Dog_Food", 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.onreadystatechange = function()
{
if (this.readyState === 4)
{
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
new_dogfood = result["Dog_Food"];
}
else
{
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
var x = formContext.getAttribute("Cat_Food");
x.setValue(new_dogfood);
}