Resources for IT Professionals > Dynamics Forums > CRM Development > Having trouble creating Fax Activity entity via Plugin
Ask a questionAsk a question
 

AnswerHaving trouble creating Fax Activity entity via Plugin

  • Tuesday, November 03, 2009 9:07 PMSrsDanG Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I've written the following function to add Fax Activities to CRM, but its crashing within the CrmService.Create call.  I can't figure out how to properly add a fax activity entity, I'd appreciate any help anyone can provide.

    public Guid CreateFaxActivity(ActivityExecutionContext executionContext, Lookup recipient, string faxNumber, string subject)
            {
                IContextService contextSvc = executionContext.GetService(typeof(IContextService)) as IContextService;
                IWorkflowContext wfContext = contextSvc.Context;
                ICrmService crmService = wfContext.CreateCrmService();
    
                fax faxActivity = new fax();
                activityparty [] recipients = new activityparty[1];
                recipients[0] = new activityparty();
                recipients[0].activitypartyid = new Key(recipient.Value);
                faxActivity.to = recipients;
                faxActivity.subject = subject;
                faxActivity.faxnumber = faxNumber;
    
                Guid crmActivityID = crmService.Create(faxActivity);
                return crmActivityID;
            }
    
    The trace log error is as follows.  It doesn't seem to be indicating a specific error message in the CRM Trace Log:
    at WorkflowHost.OnWorkflowTerminated(Object sender, WorkflowTerminatedEventArgs args)
    at WorkflowRuntime.OnScheduleTerminated(WorkflowExecutor schedule, WorkflowTerminatedEventArgs args)
    at WorkflowRuntime.WorkflowExecutionEvent(Object sender, WorkflowExecutionEventArgs e)
    at EventHandler`1.Invoke(Object sender, TEventArgs e)
    at WorkflowExecutor.FireWorkflowTerminated(Exception exception)
    at SchedulerLockGuard.FireEvents(List`1 eventList, WorkflowExecutor workflowExec)
    at SchedulerLockGuard.Dispose()
    at WorkflowExecutor.RunSome(Object ignored)
    at WorkItem.Invoke(WorkflowSchedulerService service)
    at DefaultWorkflowSchedulerService.QueueWorkerProcess(Object state)
    at _ThreadPoolWaitCallback.WaitCallback_Context(Object state)
    at ExecutionContext.runTryCode(Object userData)
    at RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
    at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at _ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
    at _ThreadPoolWaitCallback.PerformWaitCallback(Object state)
    >Workflow terminated: {B7B883A2-B5C8-DE11-967D-00155D012F03} -    at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
    at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
    at Microsoft.Crm.SdkTypeProxy.CrmService.Create(BusinessEntity entity)
    at Microsoft.Crm.Asynchronous.SdkTypeProxyCrmServiceWrapper.Create(BusinessEntity entity)
    at CrmFaxPlugin.CrmActivity.CreateFaxActivity(ActivityExecutionContext executionContext, Lookup recipient, String faxNumber, String subject) in C:\env\isvss\CrmFaxPlugin\CrmFaxPlugin\CrmActivity.cs:line 28
    at CrmFaxPlugin.AddRecipientToFaxActivity.Execute(ActivityExecutionContext executionContext) in C:\env\isvss\CrmFaxPlugin\CrmFaxPlugin\AddRecipientToFax.cs:line 87
    at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)
    at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)
    at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)
    at System.Workflow.Runtime.Scheduler.Run()

Answers

  • Tuesday, November 03, 2009 9:45 PMDavidBerry Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I think the problem is in this portion of code:

    recipients[0].activitypartyid = new Key(recipient.Value);

    activitypartyid is a unique identifier for the activityparty entity, you cannot overwrite it with the unique identifier of another record; I think you mean something like:

    recipients[0].partyid = recipient;


    Dave Berry
    • Marked As Answer bySrsDanG Wednesday, November 04, 2009 5:16 PM
    •  

All Replies

  • Tuesday, November 03, 2009 9:45 PMDavidBerry Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I think the problem is in this portion of code:

    recipients[0].activitypartyid = new Key(recipient.Value);

    activitypartyid is a unique identifier for the activityparty entity, you cannot overwrite it with the unique identifier of another record; I think you mean something like:

    recipients[0].partyid = recipient;


    Dave Berry
    • Marked As Answer bySrsDanG Wednesday, November 04, 2009 5:16 PM
    •  
  • Wednesday, November 04, 2009 5:16 PMSrsDanG Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Brilliant, thanks.

    Dan