Simple question for Dynamics CRM Version 8. I have a value (plain text field) on a record in an entity which we'll call entity1. I would like to use that value, to locate the GUID of a record in entity2 - who's record name matches that value. For example, the value of the text field in entity1 is "Test Text". Entity2 has a record named "Test Text". I need to return the GUID of that record in a variable (which i will then use to set a lookup filed). I can use something like the below, but it doesn't seem to work.
function GetGUID(FldValue) {
var RecGuid;
var req = new XMLHttpRequest(RecValue);
req.open("GET", Xrm.Page.context.getClientUrl() "/api/data/v8.2/new_entitys2?$select=new_entity2id&$filter=new_name eq" ' ' "'" FldValue "'",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 results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i ) {
var RecGuid = results.value[i]["new_entity2id"];
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}