Hi Jon ,
Hope this helps .
// JScript source code
function createPhoneCall()
{
try
{
var serverURL = Xrm.Page.context.getClientUrl() + "/api/data/v8.1/phonecalls";
var phonecallId = null;
//create activity party collection
var parties = [];
//create JSON object
var Phonecall = {};
//set fields using JSON object
//Single line of text
Phonecall["subject"] = "Phone Call";
//Single line of text & format of phone
Phonecall["phonenumber"] = "07685124677";
//Multiple Line of Text
Phonecall["description"] = "Test xxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxx";
//Date and Time
Phonecall["scheduledend"] = new Date();
//Lookup
Phonecall["regardingobjectid_account@odata.bind"] = "/accounts(475B158C-541C-E511-80D3-3863BB347BA8)"; //Regarding is an account
//ActivityParty (From)
var sender = {};
sender["partyid_systemuser@odata.bind"] = "/systemusers(21102400-932F-E611-80E5-5065F38B2611)";
sender["participationtypemask"] = 1; //From
//ActivityParty (To)
var receiver1 = {};
receiver1["partyid_account@odata.bind"] = "/accounts(475B158C-541C-E511-80D3-3863BB347BA8)";
receiver1["participationtypemask"] = 2; //To
var receiver2 = {};
receiver2["partyid_contact@odata.bind"] = "/contacts(59A0E5B9-88DF-E311-B8E5-6C3BE5A8B200)";
receiver2["participationtypemask"] = 2; //To
var receiver3 = {};
receiver3["partyid_lead@odata.bind"] = "/leads(ED975EA3-531C-E511-80D8-3863BB3CE2C8)";
receiver3["participationtypemask"] = 2; //To
//add this to collection
parties.push(sender);
parties.push(receiver1);
parties.push(receiver2);
parties.push(receiver3);
//pass parties[] to phonecall_activity_parties
Phonecall["phonecall_activity_parties"] = parties;
//Whole Number
Phonecall["actualdurationminutes"] = 300; //Duration automatically conerts into Hours
//Two Options
Phonecall["directioncode"] = true; //Direction : 0-->False/Incomming, 1-->True/Outgoing
//convert JSON object to string
var JSstring = JSON.stringify(Phonecall);
//ajax request to create phonecall activity; you have to add jquery library from SDK
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: serverURL,
data: JSstring,
beforeSend: function (CreatePhoneCallActivityRequest) {
CreatePhoneCallActivityRequest.setRequestHeader("Accept", "application/json");
CreatePhoneCallActivityRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
CreatePhoneCallActivityRequest.setRequestHeader("Prefer", "odata.include-annotations=*");
CreatePhoneCallActivityRequest.setRequestHeader("OData-MaxVersion", "4.0");
CreatePhoneCallActivityRequest.setRequestHeader("OData-Version", "4.0");
},
//Success Callback Function
success: function (data, taxtStatus, getPhoneCallActivityResponse) {
//get Response from Created Record
phonecallId = getPhoneCallActivityResponse.getResponseHeader("OData-EntityId");
//get EntityId from ResponseHeader of Created Record
phonecallId = phonecallId.split(/[()]/);
phonecallId = phonecallId[1];
//Display Enttity ID of Created Record
Xrm.Utility.alertDialog("Entity ID : " + phonecallId);
},
//Error Callback Function
error: function (CreatePhoneCallActivityRequest, textStatus, errorThrown) {
Xrm.Utility.alertDialog("Something Wrong in Script...:(");
}
});
} catch (e) {
Xrm.Utility.alertDialog(e.message + "\n" + e.description);
}
}
Thanks
Goutam