Creating Email Activity + ActivityMimeAttachment with oData in Offline mode - Help ! RRS feed

  • Question

  • Hi guys,

    I wrote some javascript code that creates an email activity with a PDF attachment. It's functional from the CRM web client (On-Premise) and using the Outlook client when I'm in online mode, but when I go OFFLINE I get the following error "The activitymimeattachment with id xxxxxxx Does Not Exist".

    I make 2 ajax calls, the first to create the Email Activity (which returns the newly created ActivityId) which I then send to my second Ajax call to create the ActivityMimeAttachment and associate it with the activity. As I said, when I'm online, it's all fine, and if I look at the ajax responses in the screenshots attached, the one that fails is looking for a ActivityMimeAttachmentId = "13F85C43-2E26-E311-96FB-005056C00008" which doesn't exist in the ActivityMimeAttachment Table. The attachment does get saved but with an id of "15F85C43-2E26-E311-96FB-005056C00008" (the SECOND number in the guid is different). If I look at the JSON response for the successfull call (when online), the value of activitymimeattachmentId is correct. 

    This is driving me NUTS ! Is there a difference between the oData service on the CRM server and service that is running on the local pc ?

    I've also included a snippet of my code.

    var ODATA_ActivityMimeAttachmentCollection = "/ActivityMimeAttachmentSet";
    var ODATA_EmailCollection = "/EmailSet";	
    var RegardingEntity = new Object();
    RegardingEntity.LogicalName = "contact";
    RegardingEntity.Id = customerid[0].id; 
    var objEmail = new Object();
    objEmail.RegardingObjectId = RegardingEntity;
    objEmail.Subject = "Contract email";
    var jsonEntity = window.JSON.stringify(objEmail);
    //* Create an email record *//
    	async : true,
    	type: "POST",
    	contentType: "application/json; charset=utf-8",
    	datatype: "json",
    	url: serverUrl + ODATA_ENDPOINT + ODATA_EmailCollection,
    	data: jsonEntity,
    	beforeSend: function (XMLHttpRequest) {
    		XMLHttpRequest.setRequestHeader("Accept", "application/json");
    	success : function (data) {
    		//** Create the email attachment **//
    		emailId = data.d.ActivityId;
    		if (emailId) {
    			var refEntity = new Object();
    			refEntity.LogicalName = "email";
    			refEntity.Id = emailId;
    			//refEntity.Name = "Subject";
    			var objAnnotation = new Object();
    			//objAnnotation.ObjectTypeCode = "email";
    			objAnnotation.Subject = "PDF Contract Document";
    			objAnnotation.ActivityId = refEntity
    			//objAnnotation.ObjectId = refEntity;
    			objAnnotation.MimeType= "application/pdf";
    			objAnnotation.Body = binaryFileToString();
    			objAnnotation.FileName = "Signed_Contract.pdf";
    			//Parse the entity object into JSON 
    			var jsonEntity2 = window.JSON.stringify(objAnnotation);
    			//AJAX function to Create a CRM record using OData 
    				async : true,
    				type: "POST",
    				contentType: "application/json; charset=utf-8",
    				datatype: "json",
    				url: serverUrl + ODATA_ENDPOINT + ODATA_ActivityMimeAttachmentCollection,
    				data: jsonEntity2,
    				beforeSend: function (XMLHttpRequest) {
    					XMLHttpRequest.setRequestHeader("Accept", "application/json");

    Wednesday, September 25, 2013 10:25 PM

All replies