如何使用MS Dynamics CRM REST Endpoint更新或删除现有电话/电子邮件记录的发件人和收件人



我正在开发一个应用程序,我需要在该应用程序中使用REST API创建和更新MS Dynamics CRM 2011中的电话/电子邮件记录。使用Soap API不是一个选项。

我已经学会了如何创建电话/电子邮件记录(这里有很好的记录或此处)。

更新现有的电话/电子邮件记录本身也不是问题。

我的问题是:如何更新现有电话/电子邮件记录的收件人和发件人字段(收件人和发件人)?

到目前为止,我已经尝试了下面描述的不同方法,但没有成功。

如果我尝试更新phonecall_activity_parties关系,我会收到Error processing request stream. Deep updates are not supported in PUT operations.错误-请参阅下面的代码

var callLogEntity = { 
"Subject": "My call", "Description": "Call comments go here" };
var activityParties = [];
activityParties.push({
"PartyId": {"Id":"4A9FD17D-5890-4BF0-94AA-D68285C46039", "LogicalName":"contact"},
"ParticipationTypeMask": { "Value": 1 }
}); // sender is a contact
activityParties.push({
"PartyId": { "Id": Xrm.Page.context.getUserId(), "LogicalName": "systemuser" },
"ParticipationTypeMask": { "Value": 2 }
}); // receiver is a current user
callLogEntity.phonecall_activity_parties = activityParties;
var restQueryUrl = "http://<crm_url>/XRMServices/2011/OrganizationData.svc/" +
"PhoneCallSet(guid'" + callLogId + "')";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
data: JSON.stringify(callLogEntity),
url: restQueryUrl,
beforeSend: function (XMLHttpRequest)
{
XMLHttpRequest.setRequestHeader("Accept", "application/json");
XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
},
success: function (data, textStatus, XmlHttpRequest)
{
console.log("Success");
},
error: function (XmlHttpRequest, textStatus, errorObject)
{
console.warn("Request FAILED: " + XmlHttpRequest.responseText);
}
});

如果我尝试使用disassociatedRecords方法与此SDK示例解除活动的关联,则会出现An activityparty cannot be disassociated from an activity错误-请参阅下面的代码

var restQueryUrl = "http://<crm_url>/XRMServices/2011/OrganizationData.svc/" +
"PhoneCallSet(guid'" + callLogId + "')/$links/" +
"phonecall_activity_parties(guid'" + activityPartyId + "')";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: restQueryUrl,
beforeSend: function (XMLHttpRequest)
{
XMLHttpRequest.setRequestHeader("Accept", "application/json");
XMLHttpRequest.setRequestHeader("X-HTTP-Method", "DELETE");
},
success: function (data, textStatus, XmlHttpRequest)
{
console.log("Success");
},
error: function (XmlHttpRequest, textStatus, errorObject)
{
console.warn("Request FAILED: " + XmlHttpRequest.responseText);
}
});

当我试图直接从ActivityPartySet中删除phonecall_activity_parties中的一个ActivityParty时,我收到了Forbidden错误。

var restQueryUrl = "http://<crm_url>/XRMServices/2011/OrganizationData.svc/" +
"ActivityPartySet(guid'" + activityPartyId + "')";
// then do an AJAX POST request with "X-HTTP-Method": "DELETE" header

从该列表中单独更新每个ActivityParty对电话记录没有影响(即,MERGE请求似乎成功,但ActivityPart方仍然指向旧记录)

var activityData = {
"PartyId":{"Id":"cc1cdb40-a844-e211-ab1a-000c297d9c06","LogicalName":"contact"},
"ParticipationTypeMask":{"Value":1}
};
var restQueryUrl = "http://<crm_url>/XRMServices/2011/OrganizationData.svc/" +
"ActivityPartySet(guid'" + activityPartyId + "')";
// then do an AJAX post request with "X-HTTP-Method": "MERGE" header
// and activityData as the message body

如果有人能说明如何更改(或删除,如"清除字段")现有电话/电子邮件记录的发件人和收件人,我将不胜感激。

你能试试这个代码吗。我希望这会有所帮助。

var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = "3D417D54-412C-440D-A390-33ED7398254D";
lookupValue[0].name = "UserName";
lookupValue[0].entityType = "systemuser";
lookupValue[1] = new Object();
lookupValue[1].id = "8BD96ECC-573D-E211-A12B-1CC1DE79B4CA";
lookupValue[1].name = "QueueName";
lookupValue[1].entityType = "queue";
createRecord(lookupValue, "EmailSet", _emailCreateSuccess, _error);
//Xrm.Page.getAttribute("to").setValue(lookupValue);

最新更新