Use SharePoint Designer 2013 workflow variables to get day of week

Learn how you can create and use workflow variables in SharePoint Designer 2013 to retrieve the name of the current day of the week based on the current date.

ADVERTISEMENTS

Just like in normal programming languages, you can create and use workflow variables in SharePoint Designer 2013 to temporarily store values or the result of calculations.

Unlike workflow parameters, which can be set from outside of a workflow, variables are always local to a workflow, so can only be set from within the workflow itself.

You can use variables to get the values of fields in the SharePoint list item the workflow is running on, or to set the values of fields in the SharePoint list item the workflow is running on. In the example shown below, you will use a workflow variable to set the value of a particular field of a SharePoint list item.

You can also use variables to store the result of a calculation or lookup. In the SharePoint Designer 2013 workflow below, you will use variables to extract the name of the current day of the week based on the date of today (current date).

To create and use SharePoint Designer 2013 workflow variables to retrieve the day of the week based on the current date:

  1. In SharePoint 2013, create a custom SharePoint list named DayOfWeek.
  2. In SharePoint Designer 2013, open the site on which the DayOfWeek SharePoint list is located.
  3. Click Site > New > List Workflow, and select DayOfWeek from the drop-down menu that appears.
  4. On the Create List Workflow dialog box, type DayOfWeekWF in the Name text box, select SharePoint 2013 Workflow from the Platform Type drop-down list box, and click OK.
  5. Click Workflow > Variables > Local Variables.
  6. On the Workflow Local Variables dialog box, click Add.
  7. On the Edit Variable dialog box, type CurrentDate in the Name text box, select Date/Time from the Type drop-down list box, and click OK.
  8. Repeat the previous two steps to add a second variable named LongDateString of type String.
  9. On the Workflow Local Variables dialog box, click OK.
  10. Place the cursor inside of Stage 1, type set, press Enter, and then select Set Workflow Variable from the drop-down menu that appears.
  11. Click workflow variable in the sentence for the workflow action, and then select Variable: CurrentDate from the drop-down list box that appears.
  12. Click value in the sentence for the workflow action, and then click the ellipsis button behind the text box.
  13. On the Date Value dialog box, leave the Current date option selected, and click OK.
  14. Place the cursor below the first action, type set, press Enter, and then select Set Workflow Variable from the drop-down menu that appears.
  15. Click workflow variable in the sentence for the workflow action, and then select Variable: LongDateString from the drop-down list box that appears.
  16. Click value in the sentence for the workflow action, and then click the formula button (second button) behind the text box.
  17. On the Lookup for String dialog box, select Workflow Variables and Parameters from the Data source drop-down list box, select Variable: CurrentDate from the Field from source drop-down list box, select Long Date from the Return field as drop-down list box, and click OK.
  18. Place the cursor below the second action, type find, press Enter, and then select Find Substring in String from the drop-down menu that appears.
  19. Click substring in the sentence for the workflow action, and then type a comma in the text box that appears.
  20. Click string in the sentence for the workflow action, and then click the formula button (second button) behind the text box.
  21. On the Lookup for String dialog box, select Workflow Variables and Parameters from the Data source drop-down list box, select Variable: LongDateString from the Field from source drop-down list box, leave As String selected in the Return field as drop-down list box, and click OK.
  22. Place the cursor below the third action, type extract, press Enter, and then select Extract Substring from Start of String from the drop-down menu that appears.
  23. Click 0 in the sentence for the workflow action, and then click the formula button behind the text box.
  24. On the Lookup for Integer dialog box, select Workflow Variables and Parameters from the Data source drop-down list box, select Variable: index from the Field from source drop-down list box, and click OK.
  25. Click string in the sentence for the workflow action, and then click the formula button (second button) behind the text box.
  26. On the Lookup for String dialog box, select Workflow Variables and Parameters from the Data source drop-down list box, select Variable: LongDateString from the Field from source drop-down list box, leave As String selected in the Return field as drop-down list box, and click OK.
  27. Place the cursor below the fourth action, type set, press Enter, and then select Set Field in Current Item from the drop-down menu that appears.
  28. Click field in the sentence for the workflow action, and then select Title from the drop-down list box that appears.
  29. Click value in the sentence for the workflow action, and then click the formula button (second button) behind the text box.
  30. On the Lookup for String dialog box, select Workflow Variables and Parameters from the Data source drop-down list box, select Variable: substring from the Field from source drop-down list box, leave As String selected in the Return field as drop-down list box, and click OK.
  31. Place the cursor in the Transition to stage section of Stage 1, and click Workflow > Insert > Action > Go to a stage.
  32. Click a stage in the sentence for the workflow action, and then select End of Workflow from the drop-down list box that appears. The final workflow should resemble the following:

    SharePoint Designer 2013 workflow to retrieve day of week using workflow variables
    Figure 1. SharePoint Designer 2013 to retrieve day of week using workflow variables.

  33. Click Workflow > Manage > Workflow Settings.
  34. On the Workflow Settings page under Start Options, select the Start workflow automatically when an item is created check box.
  35. Click Workflow Settings > Save > Publish to publish the workflow.

You should now be able to add a new list item to the DayOfWeek SharePoint list, and once the workflow has run and completed, you should see the name of the current day of the week appear in the Title field of the new list item.

Still unclear? Watch the SharePoint 2013 video tutorial below.

Related Articles

ADVERTISEMENTS