How to Use For Each Loop in NINTEX Workflow

Introduction

In this article you will see how to use a "For Each" loop in a NINTEX workflow. I will add multiple users to the specified group by calling the web service "_vti_bin/usergroup.asmx". I have created a custom list named "User Collection" that has the following columns:

  1. Group Name: A single line of text: It stores the group name to which the users will be added.
  2. Users: Person or group; multiple users can be added to this column that will be added to the specified group.

Workflow Design

Workflow Design

A Regular Expression action is used to get the user collection from the list item and stores it in the Collection workflow variable. A "For Each" action is used to loop through all the users from the collection variable and store it in a person or group workflow variable. Call the web service action used to add the users to the specified group.

Add users to group workflow

Use the following procedure to add users to a group workflow:

  1. Navigate to the User Collection list.
  2. Click on the "List" tab and then click on "Workflow Settings".
  3. Click on "Create a Workflow in Nintex Workflow".

    Create a Workflow

  4. Click on "Cancel".

    Select Blank Workflow

  5. Drag and drop the "Regular Expression" action from the "Operations" section.

    Regular expression action

  6. Click on the "Configure from Regular Expression" drop down list.
  7. Click on the "Variables" button in the ribbon interface.

    Variables button in the ribbon interface

  8. Click on the "New" button.
  9. Enter the Name as "userCollection" and variable type as "Collection".
  10. Click on "Save".

    Workflow variable

  11. The workflow variable is created successfully.
  12. Click on "Close".
  13. Get all the users from the list item and separate the values by a semicolon. Store all the users in the collection variable that we have created.

    collection variable

  14. Click on "Save".
  15. Drag and drop the "For Each" action from the "Logic and flow" section.

    Logic and flow

  16. Click on "Configure" from the "For Each" drop down list.
  17. Click on the "Variables" button in the ribbon interface.
  18. Click on the "New" button.
  19. Enter the Name as "user" and the variable type as Person or Group.
  20. Click on "Save".
  21. The Workflow variable is created successfully.
  22. Click on "Close".
  23. Drag and drop the "Call web service" action from the Integration section inside the "For Each" action.
  24. Click on "Configure" from the drop down list in the "Call web service" action.
  25. Click on the "Insert Reference" button for the URL column and then click on the "Common" tab. Select "Web URL" and then click on "Ok".

    Web URL

  26. Append "/_vti_bin/usergroup.asmx" in the URL column.
  27. Enter the User Name and Password to call the web service and then click on the "Reference" button.
  28. Click on "Ok".

    web service URL

  29. All the web service methods will be populated. Select the "AddUserToGroup" web method that will be used to add the users to the specified SharePoint group.

    AddUserToGroup web method

  30. The Web Service Input section will be populated for passing the input values to the web method.

    Web Service Input

  31. Click on the "Insert Reference" button for the groupName column and then click on "Item Properties" tab. Select the Group Name and then click on "Ok".
  32. Click on the "Insert Reference" button for the userName column and then click on the "Workflow Variables" tab. Select the user and then click on "Ok".

    Workflow Variables tab

  33. Click on "Save".

    Call Web Service

Publish the workflow

  1. Click on the "Publish" button in the ribbon interface.

    ribbon interface

  2. Ensure the Title is set; optionally you can set the values for Description and Change Comments.

    Description and Change Comments

  3. Click on the "Submit" button.

    Publishing Workflow

  4. The workflow is published successfully.

    workflow published successfully

Test the workflow

  1. Navigate to the User Collection list.
  2. Create a new item.

    Test the workflow

  3. Select the item and then click on Workflows in the ribbon interface.
  4. Click on "Add users to group workflow" and then click on the "Start" button.
  5. After a few minutes the workflow status will be changed to "Completed".
  6. Users are added successfully to the specified group.

Summary

Thus in this article you saw how to use a "For Each" loop using a NINTEX workflow.

Related Links

  1. How to Create Site Using NINTEX Workflow in SharePoint
  2. How to Delete Site Using NINTEX Workflow in SharePoint
  3. How to add user to SharePoint group using NINTEX workflow
  4. How to Remove User From SharePoint Group Using NINTEX Workflow
  5. How to Check if SharePoint Group Exists Using NINTEX Workflow
  6. How to Create User Defined Action For NINTEX Workflows in SharePoint
  7. How to Add a Group in SharePoint Site Using NINTEX Workflow
  8. How to Remove Group From SharePoint Site Using NINTEX Workflow
  9. How to Set Item Level Permission Using NINTEX Workflow in SharePoint
  10. How to Create Item in Another Site Using NINTEX Workflow in SharePoint
  11. How to Get All the Users From a Specific SharePoint Group Using NINTEX Workflow 
  12. How to Convert Word Document to PDF Using NINTEX Workflow in SharePoint       

Up Next
    Ebook Download
    View all
    Learn
    View all