Using Variables in SharePoint Designer Workflows

Thanks to everyone who attended my Form Solution End-to-End Walkthrough instructor-led lab sessions yesterday at TechReady3. Many of you asked great questions, and I received a lot of quality feedback after each session.

During one of the sessions, an attendee asked if it were possible to use variables in a Microsoft Office SharePoint Designer 2007 workflow. That same question had been asked previously by a customer hoping to resolve localization and maintenance issues related to string values.

The answer to the question is yes. SharePoint Designer allows the developer to initialize local variables that are used at runtime. To create such variables, click the Initiation button at the bottom of the Workflow Designer. Within the Workflow Parameters dialog box, you can then add as many variables as are needed during workflow execution. When adding a variable, you provide the name, data type, and default value. In the following figure, a StatusApproved string variable is created for a workflow. The default value “Approved” is set on the second page of the Add Field wizard.

Once the variables are initialized, they can be referenced in the conditions and actions within your step logic. When performing a workflow lookup, select Workflow Data from the Source list and then choose the appropriate variable from the Field list.

You can also set workflow variable values in your step logic. From the Actions list, just select More Actions and choose the Set Workflow Variable action.

31 thoughts on “Using Variables in SharePoint Designer Workflows

  1. But how do we integrate variables and strings into one value

    For example, I want to set a task to have the description:

    You have a followup meeting with (currentField:UserSelected)

  2. Hi, Steele.

    Unfortunately, the out-of-the-box "Assign a To-do Item" action does not allow you to perform a workflow lookup within the task description, as can be done in the message body when you use the "Send an Email" action. However, you can create variables that reference other variables with the "Build Dynamic String" action. This action uses a string builder that allows you to store any combination of static and dynamic text. If you want to include other variables in the string, just change the Source value in the Define Workflow Lookup dialog box to "Workflow Data".

    I hope this helps…


  3. When speaking about Workflow variables, how can I collect data from other users (and put that data back into the list)? I tried to get the data (this part was OK) into a workflow variable (there’s no other option where to store the response data), but when I assigned the value of the variable to the list item, I got only increasing numbers from 1 up. What do I not understand?
    Thanks, Ravie.

  4. Hi, Ravie.

    You might want to check your workflow start options, found on the first page of the Workflow Designer. If the workflow is set to start whenever an item is changed, then the workflow will keep getting triggered, even with an action to set a field item. I posted a workaround for this behavior (

    Otherwise, using an initiation parameter to set a list item field value should work…


  5. How can I set the workflow default initiation value to something dynamic, rather than a hardcoded value. Each workflow instance needs to evaluate which site it is on so that I can assign the approval task to the approvers group for that site. I am trying to create a generic workflow that is associated with a content type not a list. The initiation value needs to see what site is triggering the flow and then assign the proper approval group. Do you think that would be possible?

  6. Hi, Paisleygo.You could have the initiation parameter set in the first step of your workflow to the “Path” field in the current item. The Path value returns the relative location of the item (not including the item name). You could determine the site from this value.I hope this helps…Regards,David

  7. ok, i have a different approach.can you use variables on an IF var EQUALS (something different than a number?)cause everytime i try to type it wont let me. how can i tell it what value i actually want?example: i have a step that asks for a payment status. having 2 options (radio buttons) approved / declinedso if it is declined do something if it is approved do something else. thanks in advance

  8. Hi, Jesus B.You can click “Variables” at the bottom of the Workflow Designer and define Boolean, Date/Time, List Item ID, Number, or String variables. Within your step logic, you use the “Set Workflow Variable” action to update the variable value. Then, you can use conditional logic to perform actions based on that variable value.I hope this helps.Regards,David

  9. I just want to add 1000 to the item ID and then assign to a variable within the list… How on earth do I do this as it is not obvious from the workflow items.I created 2 variables – I set the first one to the list ID and the second to 1000. I then tried to add these items together with no success… am I missing something obvious? Please no code as I am only a user!!

  10. I am trying to collect approval from a person, but want to choose the person based on a field in the current item (choice made in the InfoPath form that is submitted). Is it possible to put a person into a variable that can be used in the “from” statement in the “Collect data from user” action? Have tried putting the domainusername into a variable, but haven’t gotten that to work. Do you have a working solution for that? Any help greatly appreciated

  11. Hi, Marita.I have not used the “Collect Data from a User” action very often. If memory serves me correctly, it may be looking for an ID value (for example, “9”) of a valid SharePoint user account.I hope this helps…Regards,David

  12. HiI have a project where there are 10 input fields and if those fields are filled in with data (text), based on the text that is in those fields an email should be sent, but if from those 10 fields there are equal texts like any 5 fields are filled with green color text, an email should be sent to the green color team notifying them that they have 5 green colors, and not to be notified about the other 5 fields. Any light on this 🙂 I was thinking of a way with dynamic string but if someone has done something, share it.

  13. I’m trying to set up a workflow in SPD that will compare the value in a custom list column with a value in a column in a separate custom list. Will populating a variable with one or the other pieces of data allow this?

  14. Hi, Kevin.You can use the “Compare any data source” option in the Conditions list to compare columns from different custom lists.I hope this helps…Regards,David

  15. Hi, Babylon.Are you just trying to send out an email message to specific users based on the values of certain fields? If that is the case, then you can accomplish this with conditional logic within a workflow step. Since you have 10 fields to compare, there may be a large number of “else if” branches that you have to create, but you still should be able to get the desired functionality with conditional logic.Regards,David

  16. Are workflow variables preserved? Or do they get reset each time they run? I am trying to keep a counter that I increment each time the work flow is run so that I can use it in an email within the workflow. This is for a reminder email that needs to show how many times a workflow is run. The WF var appears to get reset each time the workflow is run.TIA -Lisa

  17. Hi, Lisa.Each instance of a workflow initializes any variables used within it. In other words, values will get “reset” each time a workflow is run.I hope this helps…Regards,David

    1. David, how do I get information to save in a variable and not get updated everytime a user updates a list item? I want to set a “Finance Officer” and a Systems Officer but everytime one gets changed, so does the other.

      1. Hi, Kim.

        The best way to do that is to have the workflow fire only when an item is created (and not when it is changed). That way, the variable should not get updated when someone makes a change to the existing list item.

        I hope this helps.

        Best Regards,

  18. Thanks. Now I need to find a work around. I tried using a variable, assigning it to the work flow var for the calculation, then assigning it back to the var, but it won’t let me. Also, I was unable to find a way to do a calculation on a var, only a straight assignment. All I need is “CTR + 1” or something that tells me how many times the workflow for that item has been executed. Any insights?Thanks again.

  19. i have to Custom list in which i have a dropdown for approvers , when i fill a form by seletig the approver , the email should be send to the Selected Approver and he should update the Task.

  20. Vishal,If your drop-down list contains string values (display names), then the workflow will not be able to use that field to send email messages. Instead, you will need an email address field in the list that the workflow can use to send messages.Regards,David

  21. Hiya David great blog..I’m trying to start a workflow to email a user that has been assigned a task that has already been created (so reassigned) Is there anyway that I can trigger off a workflow when a “Field” changes and not the complete item ?

  22. Hi, Dan.Unfortunately, no. Events are tied to items, not fields within items. As a not-so-elegant workaround, you could store the “old” value in a separate field within the item and then add conditional logic to the workflow that fires actions only when the old value does not equal the new value.Regards,David

  23. Hey DavidI was thrilled to find your blog. Thanks for all the great examples! I was wondering if you know of a way to access a calculated value in a list Total (sum, count, variance, etc) from a workflow. Or, if that’s impossible, is there a way to sum all the values in 1 list column inside a workflow? Like if I had 5 entries in a list, each with $50.00 in the Cost column, I can create a view that sums the Cost values and I get a header in my list showing that the grand total is $250.00. How can I access the $250.00 value in another list or workflow?Thanks in advanceDarci

  24. Hi, Darci.There is no action that allows you to sum all list items with a SharePoint Designer workflow. Instead, if you are trying to get a sum value with a workflow, you will need to use Visual Studio.Regards,David

  25. I was wonderign if you knew how to set Workflow variables for fields from two different “Collect from User forms”. In the set workflow variable I only see the fields from my first form not the second one.

  26. Hi, Jenn.I am not sure I understand your question. When you use the “Collect Data from a User” action, the output is automatically stored to a variable. Each time you use that action, a new variable is created.Regards,David

  27. I want to send a variable comment when aproving a workflow in Project 2013, using SharePoint designer. I can send a fixed comment, but not a variable one.

Comments are closed.