See This For some background information. I am trying to do the same except im trying to auto populate a lookup field and optionset fields based on the details in a lookuprecord selected.
So i am trying to bring accross a lookfield field and optionset field, from a lookup field when it is selected.
function getVehicleDetails() { var lookUpObjectValue = Xrm.Page.getAttribute("c2_vehicle").getValue(); if ((lookUpObjectValue != null)) { var lookuptextvalue = lookUpObjectValue[0].name; var lookupid = lookUpObjectValue[0].id; //alert(lookupid); var serverUrl = Xrm.Page.context.getServerUrl(); //The XRM OData end-point var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; var odataSetName = "c2_vehicleSet"; var odataSelect = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + lookupid + "')"; //alert(odataSelect); $.ajax({ type: "GET", contentType: "application/json; charset=utf-8", datatype: "json", url: odataSelect, beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { var result_contact= data.d; //alert(result_contact.AccountNumber); //replace the fields with the fields on your entity Xrm.Page.getAttribute("c2_vehiclemake").setValue(result_contact.c2_vehiclemake); Xrm.Page.getAttribute("c2_enginetype").setValue(result_contact.c2_enginetype); }, error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); } }); } }
...
c2_vehiclemake is a lookupfield
and c2_enginetype is an optionset.
But it is not working as it is different to a normal text field.
I have tried this however, it doesent work.
var make = result_contact.c2_VehicleMake;if(make != null) {
var finalMakeID = make[0].id;
var finalMakeName = make[0].name;
var finalMakeType = make[0].entityType;
var value = new Array();
value[0] = new Object();
value[0].id = finalMakeID;
value[0].name = finalMakeName;
value[0].entityType = finalMakeType;
}
Xrm.Page.getAttribute("c2_vehiclemake").setValue(value);