I have a text field, I want to use some Javascript on it to find a related record with the same name and populate a lookup on the same form with the retrieved record.
Does anyone have a code example for this?
I was trying to use a web API request, but I believe i have some bad code around selecting a record where the name is 'eq' the same in the record being retrieved.
function retrieveAddressViaText() {
var newid = Xrm.Page.getAttribute("new_zipcode").getValue();
var req = new XMLHttpRequest();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() "/XRMServices/2011/OrganizationData.svc/new_postalcodeSet('new_PostalCode' eq '" newid "')?$select=new_State,new_City,new_Country,new_PostalCode", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
alert(results.new_PostalCodeId);
var result = JSON.parse(this.responseText).d;
var State = result.new_State;
var City = result.new_City;
var Country = result.new_Country;
var PostalCode = result.new_PostalCode;
Xrm.Page.getAttribute("new_state").setValue(State);
Xrm.Page.getAttribute("new_city").setValue(City);
Xrm.Page.getAttribute("new_country").setValue(Country);
Xrm.Page.getAttribute("new_zipcode").setValue(PostalCode);
var lookup = new Object();
var lookupValue = new Array();
lookup.id = result.new_PostalCodeId.Id;
lookup.entityType = "new_postalcode";
lookup.name = result.new_PostalCodeId.Name;
lookupValue[0] = lookup;
Xrm.Page.getAttribute("new_zipcodelookup").setValue(lookupValue);
Xrm.Page.getControl("new_zipcodelookup").clearNotification();
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}

Report
All responses (
Answers (