Blog Archives

Workaround person or group field one value problem Using Nintex Workflow 2010

nintex2010

 

So I had this problem the other day at work and wanted to share it along with the way I solved it.

First of all lets talk about how things look like:

When you have a field in SharePoint of type “person or group” that takes already defined users on the active directory of the system, you can manipulate weather this field takes one value or multiple values by the field properties page. when you insert multiple values they will be automatically separated by a semicolon as the following:

User1; User2; User3….

10

the problem is weather this filed has one user or 10, system will consider whatever there is as one value! you can make sure of that by putting the field value in a variable for instance.

So what if I needed to check every user of those for a specific reason ?! here is what was my case:

Problem Case:

The scenario was that a user enters many users that are responsible for a specific task when creating it, and a workflow works on item creation should check if one of those users is on a vacation or not, if they are, they should be replaced by their replacement that are already defined in another list in the site called employees.

Solution:

I was lucky to be using Nintex for this customer, I’m sure same solution is doable on Visual Studio but I’m not sure if it is doable if you are creating your workflow over SharePoint designer.

So to me the solution was using the very traditional way: get the filed of users as a string, split it, put the splits in a collection and loop over them to check your condition, then get them back as a string again.

For testing purposes, I’m using a 30 days trial online SharePoint site from Nintex Company, as  you have to ask for users, I’m ganna replace one user statically within the workflow, you can make it as dynamic as you want based on your requirements.

So lets see:

1- What we have:

  • A Custom List named “Assigned Tasks” having 2 added columns: Assigned Users and Result Users

User Enters the assigned users in the field no matter how many they are and and you can see users after changes done on them on the field the “users after replacement”

“you can put result in the same field but this is to show the difference”

  • List Workflow named “replace vacation Users:” that works on creation and on edit.

2- Create all the Workflow needed variables as follows:

Variable name Type Show on start form
Users as text Single Line of Text No
Users as Collection Collection No
Temp User Single Line of Text No
Result Users Text Single Line of Text No
Replacement Single Line of Text No
Result Users People or group No

3- Now moving to build some workflow actions:

– put the value of the field “Assigned users” that end user entered in the variable “Users as Text” using the action “set field value”.

 2

Now we have a string, we will split it based on the semicolon between users “;”, use the action of “regular expression” with the option split as follows:

3

use the pattern “;#” to split the users coz that’s how SharePoint read them from active directory, save result in “Users Collection”

– Now add a “ for each” action to loop on all the collection, every loop needs a temp variable for the user that will be looped on, use the “temp user” variable for that as follows:”

4

– now add your wanted condition and apply it on the temp user “remember it’s a string now”

5

– Now if the condition applies, replace the value of “temp user” with the new value that you desire, in my case was the replacement name.

now lets build the all users string back: first add the semicolon back to the temp user using the “build string” action, save the new string (user1; ) in same variable “temp user” as follows:

6

– add this user to the rest of the users string (weather it is replaced or not it’s the same), doing this step in each loop will guarantee that the result users will be in same order. use the “build string again and add the temp user to the variable “Result Users Text” as follows:

7

store the result in the same “Result Users Text”

– Now, as “people or group” field does not accept text directly, we are ganna set the “Result Users Text” in a variable of type “people or group” then we will put this variable in the field of same type:

7

– And Last but not least, put the variable value back to the field “Users After Replacement”

8

Note: if your workflow showed and error you can hunt the errors easier by creating a field of type text, put the result in it and watch what it will be, as one more semicolon might ruin adding the string to the people field.

– Before saving and publishing your workflow, make sure it works on creation via workflow settings.

So lets see it in action:
manager starts a new task, enter the name and assigned users as the following (manager does not have to check if a user is on vacation or not).

1

In my case the accountant is on a vacation and the replacement is the field Engineer (as much as illogical that is!) anyway its only for testing purposes, after adding the new Item it will show up in list as follows:

10

and that’s it! user will be changed when workflow is completed.

Just for the record, Nintex is not paying me for this Smile with tongue out Hope that helped. Enjoy Smile