SharePoint, Workflow

Sharepoint Workflow – How To Pass Value To Custom Task Form Extended Properties

So I was reading Ingo’s blog to create a custom task form for my workflow, if you need to create custom ASPX form for your custom task content-type you can go check his blog.

Basically my problem was, how to fill the custom fields inside CreateTaskByContentType activity? there’s ExtendedProperties but putting the field name on ExtendedProperties seems does not pass anything to the newly created Task.

This is my previous code

createTaskProperties.Title = "New Task";
createTaskProperties.PercentComplete = 0;
createTaskProperties.ExtendedProperties["CustomField"] = "Something";

After googling for a bit, I found a solution (sorry I forgot the URL since I *accidentally* clear my history). Basically we are still using ExtendedProperties but we can’t use the custom field name, we have to use GUID of the field.

This is the fixed code

createTaskProperties.Title = "New Task";
createTaskProperties.PercentComplete = 0;
Guid custField = workflowProperties.TaskList.Fields["CustomField"].Id;
createTaskProperties.ExtendedProperties[custField] = "Something";

Voila! the custom field in our custom task will be populated on CreateTask Activity.

Happy meddling with Workflow 🙂

4 thoughts on “Sharepoint Workflow – How To Pass Value To Custom Task Form Extended Properties

  1. Strangely I was able to SET a value in the task item using the code which did not work for you, i.e.

    createTaskProperties.ExtendedProperties[“CustomField”] = “Something”;

    I tried this using both the display name of the column AND the internal name (i.e. the value of the Name attribute on the Field definition) – both worked fine for me.

    However this didn’t work for reading back data from the task…..

    In the debugger, it was clear that the ExtendedProperties key was a GUID (of the changed column) and I had to resort to:

    Guid custField = workflowProperties.TaskList.Fields[“CustomField”].Id;

    as you suggested.

    What was odd about this is that I had to use the display name of the column as the hash table key, using the Name attribute value didn’t cut the mustard.

    Question therefore is: Why could be set the value using the “internal” name, but not read it?

  2. In your workflow project did you come across a situation of previous comments to be shown to other approvers.Let me know how to do this

    1. Yes, since this is in infopath and custom c# code.

      I was using infopath task form to get the approval comment and let the c# code to fill a hidden field in the main form (the workflow form).

      Cheap trick I know, but was stuck in finding other way

      *disclaimer, this was back then.. 2 years ago. So not sure wether there’s new feature that is better*

Leave a reply to Eru Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.