Categories

Showing posts with label Workflows. Show all posts
Showing posts with label Workflows. Show all posts

Sunday, March 11, 2012

MS CRM Workflows Waiting and Failed - How to check the error details

1. Open Advanced Find and point the entity to System Jobs
2. Add the filter criteria as defined below:
   SystemJobName Equals your_customworkflow_name
   ErrorCode ContainsData
3. Edit the columns and include MessageName, ErrorCode
4. Click Find to get the list of records that got failed in running the custom workflow with a
   detailed error message

Thursday, March 1, 2012

MS CRM Debugging Custom Workflow code

Follow the steps to succesfully start debugging of your custom workflow code in MSCRM.

1. Place the DLL and PDB files in the CRM installed path. By default, it points to following path C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly
If you are unable to paste the files, then reset the IIS and  MicrosoftCRMAsynchronous service and try.
2. Register the workflow to Disk instead of Database using PluginRegister tool
3. After sucessfully placing those files, Reset MicrosoftCRMAsynchronous service from windows services
4. Open the code on the server using Visual Studio and put a break point and press Ctrl+Alt+P that opens 'Attach to process' window.
Check these 2 fields
      1. Show processes from all users
      2. Show processes in all sessions

5. Now, select CrmAsynService.exe and click on Attach. If you are trying to debug a plugin, then attach it with w3wp.exe
6. Open the crm window and run the functionality that triggers the custom workflow and see the debugger works for you.

Thursday, February 23, 2012

Get the Context instance of ms crm workflow and plugin

To get the context of ms crm is the first phase every MS CRM developer come across when going to develop a custom workflow or plugin. The context instance of workflow or plugin gives us the details of the entity on which entity record this workflow is running which helps us to fetch more details to lead the custom logic.

//Workflow
[CrmWorkflowActivity("My Test Workflow")]
public partial class MyTestWorkflow : SequenceActivity
{
        #region Designer generated code
        ---
        ---
        #endregion
      protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
      {
         IContextService contextService = (IContextService)context.GetService(typeof(IContextService));                                  
         IWorkflowContext workflowContext = contextService.Context;
         Guid entityID = (Guid)context.OutputParameters.Properties["id"];
      }
}

//Plugin
public class Plugin:IPlugin
{
    public void Execute(IPluginExecutionContext context)
    {
        DynamicEntity entityInstance;
        if (context.InputParameters.Properties.Contains("Target") && 
               context.InputParameters.Properties["Target"] is DynamicEntity)
        {
             entityInstance= (DynamicEntity)context.InputParameters.Properties["Target"];             
        }                        
    }     
}