Using Lookup fields in Workflow Initiation forms

Let’s take another look at a commonly used field type in custom lists. Lookup fields are a nice way to generate a drop down selection list whose contents can be maintained by someone other than a site owner. Let’s say you wanted to list a set of reasons for closing an issue in your custom issues list. If you define a simple 1 column list to hold the possible choices, then reference this list and column in the definition of your lookup field, these choices can be changed at a later time without having to change the definition of the column itself.

But what if you want to use this approach in a workflow initiation form? OOTB you are kind of stuck because the possible field types for initiation form fields is much more limited that it is for a custom list.

It’s probably just me, but 5 choices seems limited. I would like to add a Lookup type so I can get the same benefits this type offers in my initiation forms.
The first thing to note on this type of customization is that SPD can destroy customizations made to your initiation forms when you add or edit a variable. Fortunately versioning is on and you can simply restore the previous version of your form if this happens, but the approach described here is a bit “outside the lines”.
OK, let’s get started. First you must know, or remember, that SPLookup fields store an Integer index to the items in it’s source list. So to begin with, we will define our form field “Reason Code” as a Number field. However, when the field is created, a declaration of this field is added to your XOML file; but this is a one-time operation unless you modfy the type of a field. Open the XOML file in SPD using the Open as XML option. The initiation form fields are declared at the top of the file.
Notice that a Number type is declared as a System.Double. Change that to System.Int32 because a user’s selection of an entry in our drop down list will be stored as an Int. Save the XOML file.
Next, we will need to open our ASP.NET initiation form page for editing. Our Reason Code field will have been generated by SPD as a textbox that includes some inline XSL.
<asp:textbox runat=”server” id=”ff1{$Pos}” text=”{format-number(@ReasonCode, ‘#,##0.00;-#,##0.00’)}” __designer:bind=”{ddwrt:DataBind(‘i’,concat(‘ff1′,$Pos),’Text’,’TextChanged’,”,ddwrt:EscapeDelims(string(”)),’@ReasonCode’)}”/>
Notice that upon postback this form element will be identified as @ReasonCode. We need to replace this ASP Textbox control with a SharePoint FormField. There are 3 attributes or parameters you will need to modify to use this markup.
<SharePoint:FormField runat=”server” id=”FormField1{$Pos}” ControlMode=”New” FieldName=”Reason_x0020_Codes __designer:bind=”{ddwrt:DataBind(‘i’,concat(‘FormField1‘,$Pos),’Value’,’ValueChanged’,’ID’,ddwrt:EscapeDelims(string(@ID)),’@ReasonCode’)}” />


The first attribute of interest is the ID field. I simply replace the ff1 notation generated by SPD with FormField1 in both places it appears. Next, supply the internal field name of the SPLookup field you are using from the same, or a different, list. Lastly we must add the last parameter required for the DataBind method of the Data View Extensions class.

Now you have to modify the <datafields> element of the Data Form web part. Your initial markup will look like this, except you will normally have more than one form field.

<datafields>@ReasonCode,Reason Code;</datafields>

To this markup we need to add the internale field name of our SPLookup; in my example this is Reason_x0020_Codes, and we must have the inner text specified as follows:

<datafields>@Reason_x0020_Codes,Reason Codes;ReasonCode,Reason Code;</datafields>

 Now we start the workflow to see our initiation form.

Also note: Editing the initiation form page in SPD will remove your internal field declaration in the datafields element. You might want to save a copy of this element and merely comment it out so you have a copy/paste reference to restore this markup. Or, like me, you can just edit the source of the ASPX page in Visual Studio or Notepad.

About generation12

I am a SharePoint/.NET consultant in the twin cities.
This entry was posted in Customization and tagged , , . Bookmark the permalink.

5 Responses to Using Lookup fields in Workflow Initiation forms

  1. Pingback: WSS 3.0 & MOSS: Recopilatorio de enlaces interesantes (XXVII)! - Blog del CIIN

  2. Pingback: WSS 3.0 & MOSS: Recopilatorio de enlaces interesantes (XXVII)! « Pasión por la tecnología…

  3. rgray00 says:

    Russ, thank you for the post. Can you please provide structure of your list(s). I’m trying to do this but can’t get it to work. Are you using a single list called Reason Codes with a field called Reason Code?

    I’d like to create a workflow on list1 using a lookup field from a separate list, list2 with fieldname field1.
    Thank you

  4. Pingback: Set choice field values in initiation form using workflow variables SPD2010? | DL-UAT

  5. Pingback: 2010 – Set choice field values in initiation form using workflow variables SPD2010? | Asking

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s