I am using Microsoft Dynamics CRM 2011 and I need to create an Annotation and attach it to a Lead within JavaScript. At the moment I have an object similar to:
var note = new Object();
note.subject = "some text";
note.notetext = "some other text";
But, I am unsure as to how define the link between the Annotation and a Lead. On a related note, when it comes to committing the these entities I would "POST" them using the OData services?
Thanks
EDIT #1: Using the info from Jason's post I've now got the following code, but it doesn't appear to be adding a node. Can someone point out where I'm going wrong?
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());
The "selectedItemId" is a GUID passed into the function. When the "readystate" field is set to 4 the containing "status" is set to 400.
EDIT #2: I have tried passing in the following string and I still get a 400 (Bad Request) response.
{ObjectTypeCode: 4, Subject: \"test note\", NoteText: \"text\", ObjectId: { ObjectIdTypeCode: 4, Id: \"" + selectedItemId + "\", LogicalName: \"lead\", Name: \"A Name\" } }
EDIT #3: OK, so if I remove the "X-HTTP-METHOD" line, wrap the "ObjectTypeCode" number 4 in quotes and remove the "ObjectIdTypeCode", then I get a 500 (Internal Error) and a code of "-2147217150".