Sunday, July 28, 2013

Lookup Activities in Visual Studio 2012

When you develop a workflow in VS 2012 you probably want to work with other lists of your SPWeb, not only the current list either the task list. But you may get this error:

 System.FormatException: Expected hex 0x in "{0}".   

Problem is that substitution "$ListId:Lists/MyList" doesn't work in flow scope.


Solution:


For the Task list of your current workflow you can use the GetTaskListId activity from "SP - Current Context" group and save task_list_id to the GUID variable. But if you want to get data from other lists of the web (for example to get data from lookup fields and other lists), issue gets more complicated. Here is a solution.
Add a property to the Elements.xml file of your Workflow like this:
 
 <File Url="Workflow.xaml" Type="GhostableInLibrary" Path="ContractorSecurityCheckWorkflow\Workflow.xaml" DoGUIDFixUp="TRUE">  
    ...  
    <Property Name="MyListId" Value="{$ListId:Lists/MyList;}" />  
 </File>  
 <File Url="WorkflowStartAssociation" Path="Workflow\WorkflowStartAssociation" Type="GhostableInLibrary">  
    ...  
    <Property Name="MyListId" Value="{$ListId:Lists/MyList;}" />  
 </File>  

and use GetConfigurationValue activity from Runtime group to save MyListId property to the string variable list_id. Then just use System.Guid.Parse(list_id).

7 comments:

  1. This works well, thanks for posting it!

    ReplyDelete
  2. Just to save you some time: in the “GetConfigurationValue” activity you need to put “MyListId” in the “Name” field 



    With Kind Regards :)
    Wim De Groote
    wimdg@hotmail.com

    ReplyDelete
  3. Hi,
    Thanks. this is very helpful in case of deployment.
    I wonder...Microsoft has nowhere suggested this workaround neither has come up with some update/patch to fix this bug till now.
    Please post some more useful stuff related to SharePoint 2013 workflow.

    ReplyDelete
  4. Thanks, Its working fine, it's save my much time.

    ReplyDelete