Thursday, June 24, 2010

Usage of Workflow Variables using SharePoint Designer 2007

At one of my client's place, I have created a couple of workflows that sends out an email to a printing press automatically when employees requests business cards on the SharePoint Intranet Portal. Created a simple list with following fields - Data Type:
1. Employee Name - String
2. Title - Choice (List of Choices)
3. Qty - Number
4. Cell # - Single Line of text
5. Office # - Choice (Drop down choice list)
6. Extn. # - Number
7. Fax # - Choice (Drop down choice List)
8. Email - Single line of text

Simple requirement, eh!
So created a workflow using SharePoint Designer 2007 for this list.
1. Created one workflow step with one action that is 'Send an Email'. Set the appropriate properties in the email body by selecting the values from the 'Current Item'.
2. Looks good so far, however, upon submission of new item, workflow generates an email and then I noticed that some fields that were empty are printed as "?????". This looks weird.

To fix the issue:
1. I created Workflow Variables and set the default values to 'x' for all of them.
2. Created workflow step for each variable and set the condition as:
a. For Cell #, for example,
Condition: If List:Cell # does not starts with x
Action: Set Variable: CellNumber to List: Cell#

Else IF - Click link 'Add 'ElseIf' Condition Branch'.
Condition:
Action: Set Variable: CellNumber to " " (without double quotes). Basically click spacebar once to put single space in the value.

3. Do it for all the variables. Note. If the Field data type is number, for example, extension number, the condition will be:
If List: Ext # is greater than 0,
4. In case of Choice type field, because choice type field values starts with a numeric value, then condition mentioned in step 2 is still valid.

5. Upon setting all workflow steps and values for conditions, the final step is to modify the 'Send an Email' step. The only change here is that instead of using List values, user variables using 'Add Lookup to body' button.

Reason of doing this drama:
When I create a variable in SharePoint Designer, the default value is set to "?????". I dont know where to change this default value. Even if the list field value is empty in the list, when workflow runs, the default value shows up as "?????" and not empty.
So it is required initialize the values by 'x', and then later resetting the value to " " (without double quotes and one space).

And if you try to check the value of the variable to "?????" then the condition will not be true, which is surprising to me. So to fix the problem, I am setting the value to 'x' first and then later if the List: field Value is empty, then resetting the variable to ' ' so that in the email body the field value should display as ' ' (without quotes) which is what customer wants to display.

Initial Workflow Email Output:
Following request submitted for printing

Employee Name : Test User
Title : Client Relationship Manager
Division : Los Angeles
Quantity : 500
Cell # : ?????
Office # : 323.923.3000
Ext. # : ?????
Fax # : 323.923.3020
Fax # (Res) : ?????
Email : ?????

After Fixing the issue, it was:
Following request submitted for printing

Employee Name : Test User
Title : Client Relationship Manager
Division : Los Angeles
Quantity : 500
Cell # :
Office # : 323.923.3000
Ext. # :
Fax # : 323.923.3020
Fax # (Res) :
Email :

Hope this helps somebody!! Send me email at Atul Shukla for questions or suggestions to improve the code.
Thanks!

No comments: