SharePoint Designer 2013 workflow loop through characters of a string

Learn how you can loop through all of the characters of a string to retrieve each character that is contained within a word from within a SharePoint Designer 2013 workflow.

ADVERTISEMENTS

SharePoint Designer 2013 comes with two looping structures you can use to perform loops in a workflow.

The first looping structure can perform a loop a specified amount of times (Loop n Times), while the second looping structure can be used to perform a loop until a specific condition is met (Loop with Condition).

For an example of using the Loop with Condition looping structure in a SharePoint Designer 2013 workflow, see SharePoint Designer 2013 workflow loop to remove spaces.

In this article, however, you'll be using the Loop n Times looping structure in a SharePoint Designer 2013 workflow to loop a specific amount of times through a string to retrieve each character that the string contains.

The example shown below will be kept simple and the results written to the history list of the workflow. For a more practical example of the technique used below, see Convert strings to uppercase or lowercase in a SharePoint Designer 2013 workflow.

Loop through all of the characters of a string in a SharePoint workflow

  1. In SharePoint 2013, create a new SharePoint list named MyList that has one column named Title.
  2. In SharePoint Designer 2013, create a new List Workflow that runs on the MyList SharePoint list. Name the workflow GetAllCharsWF and leave SharePoint 2013 Workflow selected as the Platform Type.
  3. Create a local variable of type String named MyString.
  4. Follow steps 4 through 6 of SharePoint Designer 2013 workflow string length retrieval, but then use the MyString variable you created instead of the StringLength variable.
  5. Create a second local variable of type Integer named counter.
  6. Add a Set Workflow Variable action to the SharePoint workflow, and configure it to say:

    Set Variable: counter to -1
  7. Click to place the cursor below the last action you added, and then select Workflow > Insert > Loop > Loop n Times, and configure the sentence for the loop to say:

    The contents of this loop will run Variable: index times
  8. Click to place the cursor inside the loop, and then add a Do Calculation action to the SharePoint workflow, and configure it to say:

    Calculate Variable: counter plus 1 (Output to Variable: calc )
  9. Add an Extract Substring of String from Index with Length action to the SharePoint workflow, and configure it to say:

    then Copy from Variable: MyString, starting at Variable: calc for 1 characters (Output to Variable: substring )
  10. Add a Log to History List action to the SharePoint workflow, and configure it to say:

    then Log Variable: substring to the workflow history list
  11. Add a Set Workflow Variable action to the SharePoint workflow, and configure it to say:

    Set Variable: counter to Variable: calc
  12. End the SharePoint workflow with a Go to a stage action.
  13. Configure the SharePoint workflow to start automatically when an item is created.
  14. Publish the workflow to SharePoint 2013.

In SharePoint 2013, navigate to the MyList SharePoint list and add a new item. Once the workflow has run and completed, navigate to the workflow history list, and verify that each character that is contained in the text you entered for the Title field of the list item appears on a separate line in the workflow history list.

Related Articles

ADVERTISEMENTS