Convert string workflow variable to number in SharePoint Designer 2010
Learn how you can use the 'Return field as' setting on the 'Lookup for Number' dialog box in SharePoint Designer 2010 to convert a string workflow variable to a number.
In SharePoint Designer 2010 you have the option to create workflow variables that have one of the following data types:
- List Item Id
Suppose you have defined two workflow variables in a SharePoint Designer workflow:
- stringVar with data type String
- numberVar with data type Number
Now you want to set the value of stringVar to the value of a "Single line of text" field named NumberAsString in the Current Item, and then convert that string to a number and add 1.5 to it.
You can use the Return field as drop-down list box on the Lookup for Number dialog box to convert a string variable to a number.
To convert a string workflow variable to a number and then add 1.5 to it:
- Create a new SharePoint Designer 2010 List Workflow and associate it with the SharePoint list that contains the NumberAsString field.
- Add a Set Workflow Variable workflow action to Step 1 of the workflow to set the value of the stringVar variable to the value of NumberAsString in the Current Item.
- Add a Set Workflow Variable workflow action to Step 1 of the workflow to set the value the numberVar variable to the value of the stringVar variable. Here is where you convert the value of the stringVar variable to a number by setting the value of numberVar to the value of stringVar and on the Lookup for Number dialog box set the Return field as to As Double.
Figure 1. Lookup for Number dialog box in SharePoint Designer 2010.
- Add a Do Calculation workflow action to Step 1 of the workflow to add 1.5 to the value of the numberVar variable.
- Add a Log to History List workflow action that logs the value of numberVar as a String to the history list as a way of debugging the SharePoint Designer workflow.
The final SharePoint Designer workflow should resemble the following figure:
Figure 2. SharePoint Designer 2010 workflow to convert string workflow variable to number.
- How to create a List Workflow in SharePoint Designer 2010
- SharePoint Designer 2010 workflow to set time portion of a date/time
- Construct a date from strings in a SharePoint Designer 2010 workflow