Hello all,
when i create new appointment on account form its all contact add in
Required party list. how i can solve this any Idea. using javascript .
1 On account
my code is
on new appointment form load
function newAppointment() {
var formType = Xrm.Page.ui.getFormType();
if (formType == 1) {
var lookupData = Xrm.Page.getAttribute("requiredattendees").getValue();
var accountId = lookupData[0].id;
var accountName = lookupData[0].name;
var accountName = lookupData[0].entity;
var guid = accountId.replace("{", "").replace("}", "");
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts?$select=contactid,fullname&$filter=_parentcustomerid_value eq "+guid, false);
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);
debugger;
for (var i = 0; i < results.value.length; i++) {
var contactid = results.value[i]["contactid"];
var fullname = results.value[i]["fullname"];
var lookupData = new Array();
var lookupItem = new Object();
//Set the value of a Lookup field
lookupItem.id = contactid;
lookupItem.name = fullname;
lookupItem.entityType = "contact";
lookupData[0] = lookupItem;
Xrm.Page.getAttribute("requiredattendees").setValue(lookupData);
// Xrm.Page.getAttribute("requiredattendees").setValue(lookupData);
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
////////////////////////////////////////
} else {
alert(formType);
}
}
*This post is locked for comments