在动态crm 2011中附加一条注释

时间:2012-07-10 14:35:57

标签: dynamics-crm dynamics-crm-2011

我正在使用Microsoft Dynamics CRM 2011,我需要创建一个Annotation并将其附加到JavaScript中的Lead。目前我的对象类似于:

var note = new Object();
note.subject = "some text";
note.notetext = "some other text";

但是,我不确定如何定义Annotation和Lead之间的链接。在相关的说明中,当涉及提交这些实体时,我会使用OData服务“POST”它们吗?

由于

编辑#1:使用Jason的帖子中的信息我现在得到了以下代码,但它似乎没有添加节点。有人能指出我出错的地方吗?

var note = new Object();
note.subject = "Test Note";
note.notetext = "some test text";
note.objectid = { id: selectedItemId, logicalname: "lead", name: "A Name" };

var postRequest = new XMLHttpRequest();
postRequest.open( "POST", url + "/LeadSet(guid'" + selectedItemId.toString() + "')", true );
postRequest.setRequestHeader( "Accept", "application/json" );
postRequest.setRequestHeader( "Content-Type", "application/json;charset=utf-8" );
postRequest.setRequestHeader( "X-HTTP-Method", "MERGE" );

postRequest.onreadystatechange = function() {
    if( this.readyState == 4 )
    {
        var text = "complete";
    }
};

postRequest.send(note.toString());

“selectedItemId”是传递给函数的GUID。当“readystate”字段设置为4时,包含的“status”设置为400。

编辑#2:我尝试传入以下字符串,但仍然收到400(错误请求)响应。

{ObjectTypeCode: 4, Subject: \"test note\", NoteText: \"text\", ObjectId: { ObjectIdTypeCode: 4, Id: \"" + selectedItemId + "\", LogicalName: \"lead\", Name: \"A Name\" } }

编辑#3:好的,所以如果我删除“X-HTTP-METHOD”行,将“ObjectTypeCode”编号4包装在引号中并删除“ObjectIdTypeCode”,然后我得到500(内部错误)和代码“-2147217150”。

1 个答案:

答案 0 :(得分:0)

您可以像这样创建参考:

note.Subject = "TEST"; 
note.NoteText = "123"; 
note.ObjectId = { Id: "8343E0C3-76C9-E111-A3BC-000C29336979", LogicalName: "lead", Name: "test lead" };