forge

Adding CreateTask Activity to a SharePoint Workflow

Sometimes things aren’t as easy as they seem.  Adding a CreateTask activity to a SharePoint Workflow is one of those things.  Drag-and-Drop and you’re ready to go.  Not quite.  There are several things that you need to know about adding a CreateTask Activity.

First, you need to know about Correlation tokens.  Basically, the task needs a different correlation token than the workflow itself.   You can find the documentation for this in the SDK under Server Technologies\Windows SharePoint Services 3.0\SDK Documentation\General Reference\Workflows in Windows SharePoint Services\Workflow Development for Windows SharePoint Services\Workflow Development in Visual Studio 2005\Workflow Activities Overview\Correlation Tokens in Workflows.  You can also read Eilene Hao’s post on the SharePoint Team Blog titled “Developing Workflows in VS: Part 3 – Five Steps for Developing Your Workflow”.

Next, you have to do some manual manipulation of the code for the workflow to define the appropriate properties and get them setup for the activity’s use.   In the SDK documentation at Office solutions Development\SharePoint Server 2007\SDK Documentation\General Reference\Managing Enterprise Document Content\Workflows in Office SharePoint Server 2007\Walkthrough: Creating Office SharePoint Server 2007 Workflows in Visual Studio\Step 1: Create the Workflow there is a section “Adding and Configuring Workflow Activities\To add the CreateTask activity” which contains a suggestion for the properties to be set – and more importantly some code you’ll need to get the task to work correctly.

The net of it is that you must declare public fields tasked as a Guid – and get a new Guid in the value when the MethodInvoking is called.  You must also declare and new a Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties.  These must be assigned to the TaskId and TaskProperties of the activity respectively.

If for some reason you fail to do this you may see an error in the log like the following:

[Note: You don’t have to read through the following, it’s mainly included here so that it can be indexed so if someone is searching for the cause of the error they might find it.  Rlb]

Help Your SharePoint User

11/29/2006 22:30:43.57 w3wp.exe (0x00C4)                       0x0C6C Windows SharePoint Services   Workflow Infrastructure                       88xr       Unexpected       WinWF Internal Error, terminating workflow Id# 4a62891e-f779-499c-86d1-a2362f461978

11/29/2006 22:30:43.58 w3wp.exe (0x00C4)                       0x0C6C Windows SharePoint Services   Workflow Infrastructure                       98d4      Unexpected       System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.NullReferenceException: Object reference not set to an instance of an object.     at Microsoft.SharePoint.Workflow.SPWinOETaskService.CreateTaskWithContentTypeInternal(Guid taskId, SPWorkflowTaskProperties properties, Boolean useDefaultContentType, SPContentTypeId ctid, HybridDictionary specialPermissions)     at Microsoft.SharePoint.Workflow.SPWinOETaskService.CreateTask(Guid taskId, SPWorkflowTaskProperties properties, HybridDictionary specialPermissions)     — End of inner exception stack trace —     at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)    …

11/29/2006 22:30:43.58*               w3wp.exe (0x00C4)                       0x0C6C Windows SharePoint Services   Workflow Infrastructure                    98d4      Unexpected       … at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)     at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)     at System.Workflow.Activities.CallExternalMethodActivity.Execute(ActivityExecutionContext executionContext)   …

11/29/2006 22:30:43.58*               w3wp.exe (0x00C4)                       0x0C6C Windows SharePoint Services   Workflow Infrastructure                    98d4      Unexpected       …  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()

Or

11/29/2006 22:18:01.14 w3wp.exe (0x0D18)                       0x0AB0 Windows SharePoint Services   Workflow Infrastructure                       72ev      Medium               Value cannot be null.

11/29/2006 22:18:01.31 w3wp.exe (0x0D18)                       0x0AB0 Windows SharePoint Services   Workflow Infrastructure                       88xr       Unexpected       WinWF Internal Error, terminating workflow Id# b0474e92-3e38-443e-9ac1-c27afb1d20cf

11/29/2006 22:18:01.31 w3wp.exe (0x0D18)                       0x0AB0 Windows SharePoint Services   Workflow Infrastructure                       98d4      Unexpected       System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.ArgumentNullException: Value cannot be null.     at Microsoft.SharePoint.Workflow.SPWorkflow.GetReservedItemId(SPList list, Guid taskId, Boolean createNew)     at Microsoft.SharePoint.Workflow.SPWorkflowInstanceBase.GetReservedItemId(SPList list, Guid taskId)     at Microsoft.SharePoint.Workflow.SPWinOETaskService.CreateTaskWithContentTypeInternal(Guid taskId, SPWorkflowTaskProperties properties, Boolean useDefaultContentType, SPContentTypeId ctid, HybridDictionary specialPermissions)     at Microsoft.SharePoint.Workflow.SPWinOETaskService.CreateTask(Guid taskId, SPWorkflowTaskProperties properties, HybridDictionary specialPermissions)     — End of inner exception stack trac…

11/29/2006 22:18:01.31*               w3wp.exe (0x0D18)                       0x0AB0 Windows SharePoint Services   Workflow Infrastructure                    98d4      Unexpected       …e —     at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)     at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)     at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, Parame…

11/29/2006 22:18:01.31*               w3wp.exe (0x0D18)                       0x0AB0 Windows SharePoint Services   Workflow Infrastructure                    98d4      Unexpected       …terModifier[] modifiers, CultureInfo culture, String[] namedParams)     at System.Workflow.Activities.CallExternalMethodActivity.Execute(ActivityExecutionContext executionContext)     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()

(These are located in the Universal Logging Service log at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\LOGS)

8 replies
  1. Tom Cairy
    Tom Cairy says:

    Robert – I was wondering if you knew of a gallery of workflow activities (free or purchasable) .. I am looking to have a workflow detach a ile when an email is received into a document library .. know of such a thing?

  2. Robert Vignato
    Robert Vignato says:

    I have a question on Content Types for your chapter in the Real World book…
    1) How do you create the files (and the Field Ref ID GUID)
    2) Where do they go and how do you deploy them?

    This hardly touched on in your section of the book.

    Please help… I’m stuck.

    Thanks,
    Robert Vignato

  3. lazyproggie
    lazyproggie says:

    had a similar exception. the problem was the custom content type i created for the task form wasn’t added in the custom list as one of its content types.

Comments are closed.