0
votes

I am working on a Custom Workflow within CRM 2011. I have created the workflow to create a couple of records (invoice and invoice product) once I get a particular type of Activity (a custom activity). During the testing I passed the particular GUID of the entity I would be working with (the creation of said entity would be the trigger for the workflow). The workflow works fine when I pass in a GUID for the record I want to work with. However, once I load the dll File inside CRM and attempt to trigger the workflow it goes into a waiting status and stays there. I have try catch blocks on all of my functions with a throw new InvalidPluginExecutionException("Error occurred in MethodName:" + ex.Message);. It does not fail or stop but just continues in a waiting status.

I have tried to Reset :

  • IIS
  • async service
  • Sync Services (Have Tried Edit:
  • Adding Version Control
  • Uninstall / Reinstall assembly)

Currently I am attempting to pull the activity id of the PrimaryEntityId as my primary entity is the record I need to use for the workflow. The only thing that I need from that record is the ID.

public String GetFeeId(WorkFlowHelper workFlowHelper, CodeActivityContext executionContext)
    {
        String feeRecordId = string.Empty;
        try
        {
            var primaryEntity = workFlowHelper.workFlowContext.PrimaryEntityId;
            if (primaryEntity != null)
            {
                feeRecordId = workFlowHelper.workFlowContext.PrimaryEntityId.ToString();
            }
            if (primaryEntity == null)
            {
                workFlowHelper.WorkFlowError("Primary Entity is null");
            }
        }
        catch (Exception ex)
        {
            if (workFlowHelper.debugMessagesOn == true)
            {
                Console.WriteLine("Id is blank!");
            }
            workFlowHelper.WorkFlowError(ex.ToString());
            throw new InvalidPluginExecutionException("Error occured in ConnectionInfo Method:" + ex.Message);
        }
        return feeRecordId;

Any ideas on what could be causing this?

Thanks,

2

2 Answers

1
votes

It sounds like CRM may be having a problem loading your assembly, or confusing it for an older version of the same assembly.

Are you versioning your workflow assembly while you develop and deploy it, and is the assembly signed with a strong-name key?

In Visual Studio on the Project tab, make sure you increment the Build/Revision number. See this article: http://gonzaloruizcrm.blogspot.com/2011/08/assembly-versioning-in-crm-2011.html

If you don't increment the Build/Revision, CRM may not see your updated assembly as an "update" and may be trying to use an older, cached version, which can cause all kinds of problems.

You may also try unregistering the assembly completely and then registering your latest version. You might need to update your workflows as well.

0
votes

Here's the most simplest way (taken out your WorkFlowHelper)..

public String GetFeeId(CodeActivityContext executionContext)
{
    // Create the context
    var context = executionContext.GetExtension<IWorkflowContext>();
    var feeRecordId = context.PrimaryEntityId
}