Убедитесь, что вы не используете URL-адрес, например /api/data/v8.0/activityparties
, для создания объектов деятельности. Вы должны всегда ориентироваться на отдельный тип деятельности как emails
или tasks
или phonecalls
как конечная точка /api/data/v8.0/emails
, так как все отдельные действия создадут activitypointers
, activityparties
в фоновом режиме. Подробнее о сложной сущности "Activity"
Вы не можете создавать записи сущности Party Activity напрямую, так как эта сущность поддерживает только сообщение RetrieveMultiple
, но не Create
или Update
. Узнать больше
Пример кода для создания группы действий и заданий группы действий
///------------ Create Phone Call Activity ----------
function createPhoneCall() {
try {
//declare variables
var phonecallId = null;
var stringJSONPhone = null;
var urlPhone = null;
//create activity party collection
var parties = [];
//create JSON object
var JSONPhone = {};
//set fields using JSON object
//Single line of text
JSONPhone["subject"] = "Test Phone Call"; //Subject
//Single line of text & format of phone
JSONPhone["phonenumber"] = "9876543210"; //Phone Number
//Multiple Line of Text
JSONPhone["description"] = "Phone Call Activity for Testing Purpose only...!"; //Description
//Date and Time
JSONPhone["scheduledend"] = new Date(); //Due
//Lookup
JSONPhone["regardingobjectid_account@odata.bind"] = "/accounts(B386D403-F7AD-E511-80DC-A45D36FC4F90)"; //Regarding is an account
//ActivityParty (From)
var sender = {};
sender["partyid_systemuser@odata.bind"] = "/systemusers(D949B11D-9240-4037-8379-F31C7A36680E)";
sender["participationtypemask"] = 1; //From
//ActivityParty (To)
var receiver1 = {};
receiver1["partyid_account@odata.bind"] = "/accounts(B386D403-F7AD-E511-80DC-A45D36FC4F90)";
receiver1["participationtypemask"] = 2; //To
var receiver2 = {};
receiver2["partyid_contact@odata.bind"] = "/contacts(DFE54660-37CD-E511-80DE-6C3BE5A831DC)";
receiver2["participationtypemask"] = 2; //To
var receiver3 = {};
receiver3["partyid_lead@odata.bind"] = "/leads(ED81F0D9-37CD-E511-80DE-6C3BE5A831DC)";
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
JSONPhone["phonecall_activity_parties"] = parties;
//Whole Number
JSONPhone["actualdurationminutes"] = 25; //Duration
//Two Options
JSONPhone["directioncode"] = true;//Direction : 0-->False/Incoming, 1-->True/Outgoing
//convert JSON object to string
stringJSONPhone = JSON.stringify(JSONPhone);
//url for ajax request to create phonecall activity
urlPhone = Xrm.Page.context.getClientUrl() + "/api/data/v8.0/phonecalls";
//ajax request to create phonecall activity
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: urlPhone,
data: stringJSONPhone,
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);
}
}
Ссылка на код