Hi guys
So I have seen similar threads but couldn't quite get this right as I think my requirement is slightly different. Basically I have an entity WhatsApp on this entity I have a field "icon_mobile" i am trying to write a script that searches the contact entity for the mobile number which sits in "icon_mobile" by searching the "mobilephone" field in the contact entity, then prepopulates the "from" field on the whatsapp entity. Here is my crack thus far, script is running but using the debugger there seemed to be an issue with my send();
function contactPrePopulation() {
debugger;
var mobile = Xrm.Page.getAttribute("icon_mobile").getValue();
//var mobileNumber = "27" + mobile.substr(1);
if(mobile === null) {
return;
}
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/contact?&select=contactid&$filter=mobilephone eq guid' " + mobile[0].id + "'";
var retriveReq = new XMLHttpRequest();
retriveReq.open("GET", oDataSelect, false);
retriveReq.setRequestHeader("Accept", "application/son");
retriveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
retriveReq.onreadystatechange = function() {
GetContactData(this);
};
retriveReq.send();
}
function GetContactData(retriveReq) {
if(retriveReq.readyState == 4) {
if(retriveReq.status == 200) {
var retrieved = JSON.parse(retriveReq.responseText).d;
Xrm.Page.getAttribute("from").setValue(retrieved.results[0].mobile);
}
}
alert("Hello!");
}
function contactPrePopulation() {
debugger;
var mobile = Xrm.Page.getAttribute("icon_mobile").getValue();
//var mobileNumber = "27" + mobile.substr(1);
if(mobile === null) {
return;
}
var serverUrl = Xrm.Page.context.getClientUrl();
var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/contact?&select=contactid&$filter=mobilephone eq guid' " + mobile[0].id + "'";
var retriveReq = new XMLHttpRequest();
retriveReq.open("GET", oDataSelect, false);
retriveReq.setRequestHeader("Accept", "application/son");
retriveReq.setRequestHeader("Content-Type", "application/json;charset=utf-8");
retriveReq.onreadystatechange = function() {
GetContactData(this);
};
retriveReq.send();
}
function GetContactData(retriveReq) {
if(retriveReq.readyState == 4) {
if(retriveReq.status == 200) {
var retrieved = JSON.parse(retriveReq.responseText).d;
Xrm.Page.getAttribute("from").setValue(retrieved.results[0].mobile);
}
}
alert("Hello!");
}