Hi,
This has been asked before and i'm using the same script:
https://community.dynamics.com/crm/f/117/t/107172
It works great for populating static fields, but it doesn't seem to work with a lookup field. Could someone point me in the right direction to get this to work please?
Code sample:
function Contact_OnChange() { var contact = Xrm.Page.getAttribute("new_contactid").getValue(); if (contact == null) { return; } var serverUrl = Xrm.Page.context.getClientUrl(); var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/ContactSet?$select=MobilePhone&$filter=ContactId eq guid'" + contact[0].id + "'"; var retrieveReq = new XMLHttpRequest(); retrieveReq.open("GET", oDataSelect, false); retrieveReq.setRequestHeader("Accept", "application/json"); retrieveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8"); retrieveReq.onreadystatechange = function () { GetContactData(this); }; retrieveReq.send(); } function GetContactData(retrieveReq) { if (retrieveReq.readyState == 4) { if (retrieveReq.status == 200) { var retrieved = JSON.parse(retrieveReq.responseText).d; Xrm.Page.getAttribute("new_numberfield").setValue(retrieved.results[0].MobilePhone); } } }
Kind Regards,
Matt