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.

ADVERTISEMENTS

In SharePoint Designer 2010 you have the option to create workflow variables that have one of the following data types:

Suppose you have defined two workflow variables in a SharePoint Designer workflow:

  1. stringVar with data type String
  2. 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:

  1. Create a new SharePoint Designer 2010 List Workflow and associate it with the SharePoint list that contains the NumberAsString field.
  2. 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.
  3. 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.

    Lookup for Number dialog box in SharePoint Designer 2010

    Figure 1. Lookup for Number dialog box in SharePoint Designer 2010.

  4. Add a Do Calculation workflow action to Step 1 of the workflow to add 1.5 to the value of the numberVar variable.
  5. 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:

SharePoint Designer 2010 workflow to convert string workflow variable to number

Figure 2. SharePoint Designer 2010 workflow to convert string workflow variable to number.

Related Articles

ADVERTISEMENTS