Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Error creating attachment for email in plugin

$
0
0

I'm trying to copy a document in a note and attach it to an email which is also created in the plugin. I'm using CRM Online.

The attribute I'm having trouble with is ObjectTypeCode.

Entity attachment = new Entity("activitymimeattachment");//GetAttachment(service, (Guid)noteCol.Entities[0].Attributes["annotationid"]);
attachment["filename"] = note.Contains("Containsfilename") ? note["filename"] : "";
attachment["body"] = note.Contains("documentbody") ? note["documentbody"] : "";
attachment["mimetype"] = note.Contains("mimetype") ? note["mimetype"] : "";
attachment["subject"] = note.Contains("subject") ? note["subject"] : "";
attachment["objectid"] = new EntityReference("email", emailid);
attachment["objecttypecode"] = email.LogicalName;//4202;// "email";// new OptionSetValue(4202);

I have tried several ways to get the ObjectTypeCode but keep getting an error when the attachment is created. I get the error "An unexpected error occurred". Full trace:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: An error occurred in the CreditControlClass plug-in:An unexpected error occurred.

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at Microsoft.Crm.Sandbox.SandboxOrganizationService.Execute(String operation, Byte[] serializedRequest)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [1]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.Crm.Sandbox.ISandboxOrganizationService.Execute(String operation, Byte[] serializedRequest)
   at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.ExecuteInternal(OrganizationRequest request)
   at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.CreateInternal(Entity entity)
   at CreditControl.CreditControlClass.Execute(IServiceProvider serviceProvider)Detail: <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts"><ErrorCode>-2147220891</ErrorCode><ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic"><KeyValuePairOfstringanyType><d2p1:key>OperationStatus</d2p1:key><d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value></KeyValuePairOfstringanyType><KeyValuePairOfstringanyType><d2p1:key>SubErrorCode</d2p1:key><d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value></KeyValuePairOfstringanyType></ErrorDetails><Message>An error occurred in the CreditControlClass plug-in:An unexpected error occurred.

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc&amp; rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at Microsoft.Crm.Sandbox.SandboxOrganizationService.Execute(String operation, Byte[] serializedRequest)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]&amp; outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [1]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
   at Microsoft.Crm.Sandbox.ISandboxOrganizationService.Execute(String operation, Byte[] serializedRequest)
   at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.ExecuteInternal(OrganizationRequest request)
   at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.CreateInternal(Entity entity)
   at CreditControl.CreditControlClass.Execute(IServiceProvider serviceProvider)</Message><Timestamp>2013-12-11T09:45:25.8504856Z</Timestamp><InnerFault i:nil="true" /><TraceText>

[CreditControl: CreditControl.CreditControlClass]
[68cfa5ce-a961-e311-9718-d89d6763ff8c: CreditControl.CreditControlClass: Update of invoice]

ENTER: CreditControlClass.Execute
Retrieve Note
Build attachment
Create attachment


</TraceText></OrganizationServiceFault>





Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>