SharePoint Designer 2013 workflow string length retrieval

Learn how you can retrieve the length of a string from within a SharePoint Designer 2013 workflow.

ADVERTISEMENTS

Problem

SharePoint Designer workflows do not offer a string-length function you can use to retrieve the length of a string from within the workflow.

Solution

You can use a workaround to be able to determine the length of a string without having to write any custom actions to be able to do so.

To retrieve the length of a string in a SharePoint Designer 2013 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 GetStringLengthWF and leave SharePoint 2013 Workflow selected as the Platform Type.
  3. Create a local variable of type String named StringLength.
  4. Add a Set Workflow Variable action to the SharePoint workflow, and configure it to say:

    Set Variable: StringLength to Current Item:Title
  5. Add a Set Workflow Variable action to the SharePoint workflow, and configure it to say:

    then Set Variable: StringLength to [%Variable: StringLength%]^
  6. Add a Find Substring in String action to the SharePoint workflow, and configure it to say:

    then Find ^ in Variable: StringLength (Output to Variable: index)
  7. Add a Log to History List action to the SharePoint workflow, and configure it to say:

    then Log Variable: index to the workflow history list
  8. End the SharePoint workflow with a Go to a stage action.
  9. Configure the SharePoint workflow to start automatically when an item is created.
  10. 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 the length of the string was written to it and is correct.

Discussion

In the solution described above, you learned how to retrieve the length of a string from within a SharePoint Designer 2013 workflow. You thereby learned that you can append a character to the end of a string, and then retrieve the index number of that character to be able to determine the length of the string.

You can use any character for string length retrieval, but note however that the character you choose to use must be unique and not used as part of the string, otherwise the string length retrieval will fail.

After you have retrieved the length of a string, you can use the length to for example loop though all of the characters of the string.

Related Articles

ADVERTISEMENTS