3

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

我已经弄清楚如何创建电话/电子邮件记录(在此处此处有详细记录)。

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

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

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

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

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

如果我尝试使用此 SDK 示例An activityparty cannot be disassociated from an activity中的 disassociateRecords 方法取消关联活动,我会收到错误- 请参阅下面的代码

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

当我Forbidden尝试直接从 ActivityPartySet 删除 phonecall_activity_parties 中找到的 ActivityParty 之一时出现错误。

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

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

4

1 回答 1

0

你可以试试这个代码。我希望这会有所帮助。

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);
于 2013-01-02T10:03:34.433 回答