Set the current time using a SharePoint Designer 2010 workflow

Learn how you can use an Update List Item workflow action in SharePoint Designer and the workflow context to set a field in a SharePoint list to the value of the current time.

ADVERTISEMENTS

Problem

You have a SharePoint list that contains a text field named CurrentTime in which you want to save the current time (without the date) by using a SharePoint Designer 2010 workflow.

Solution

You can retrieve the current date and time from the workflow context and then use this to return the time as a short time.

Discussion

To use a SharePoint Designer workflow to set the current time:

  1. Create a new SharePoint Designer 2010 List Workflow and associate it with the SharePoint list that contains the CurrentTime field.
  2. Select Action > List Actions > Update List Item to add an Update List Item workflow action to Step 1.
  3. Click this list in the Update List Item workflow action.
  4. On the Update List Item dialog box, leave Current Item selected in the List drop-down list box, and then click Add.
  5. On the Value Assignment dialog box, select CurrentTime from the Set this field drop-down list box, and then click the formula button behind the To this value text box.
  6. On the Lookup for Single line of text dialog box, select Workflow Context from the Data source drop-down list box, select Date and Time Started from the Field from source drop-down list box, select Short Time from the Return field as drop-down list box, and click OK.
  7. Click OK when closing all open dialog boxes.
  8. Publish the SharePoint Designer workflow to SharePoint and test it.

The final SharePoint Designer 2010 workflow should resemble the following figure:

SharePoint Designer workflow action used to set the current time
Figure 1. SharePoint Designer workflow action used to set the current time.

And the chain of dialog boxes used to construct the inner workings of the SharePoint Designer workflow action should resemble the following figure:

Setting the current time through SharePoint Designer workflow dialog boxes
Figure 2. Setting the current time through SharePoint Designer workflow dialog boxes.

Now as soon as the workflow has run the CurrentTime field should contain a time such as for example 10:39 PM.

Related Articles

ADVERTISEMENTS