【问题标题】:How to update or delete Sender and Receiver of an existing phonecall / email record using MS Dynamics CRM REST Endpoint如何使用 MS Dynamics CRM REST Endpoint 更新或删除现有电话/电子邮件记录的发件人和收件人
【发布时间】:2012-12-06 04:00:00
【问题描述】:

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

我已经想出了如何创建电话/电子邮件记录(这是有据可查的herehere)。

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

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

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

如果我尝试更新 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);
    }
});

如果我尝试使用来自 this SDK Example 的 disassociateRecords 方法取消关联活动,则会收到 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 请求似乎成功,但 ActivityParty 仍指向旧记录)

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

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

【问题讨论】:

  • 你解决过这个问题吗?
  • 不,从来没有解决过这个问题。我的解决方法是在保证最终的保存操作之前不要将发送者/接收者添加到电话中。这是可以接受的,因为我的代码正在创建全新的电话。但是,如果电话记录已经存在于 CRM 中,那我就不走运了。

标签: javascript rest dynamics-crm-2011 dynamics-crm


【解决方案1】:

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

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);

【讨论】:

  • 我认为这不会起作用,因为我的代码必须在任何表单页面上运行,而不仅仅是在实际的电话/电子邮件表单页面上。我不明白这如何从主页上工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-03
  • 1970-01-01
相关资源
最近更新 更多