another technical blog...technically

Sunday, December 7, 2014

Get user in SharePoint 2013 workflows

Today i'll present you a resolution of a common question when dealing with SharePoint 2013 workflows:
How the hell i get the user login name from a type user field?
The answer should be straighforward, unfortunally it isn't: it depends from the user field xml parameters.
Site columns
It is possible to declare a user field in defferent ways, so, reusing Example 01 code, i have extended the workflow item content type, so i can make some tests with those three different fields:
  1. Approvers (Type = UserMulti): used for multiple users
  2. Type User - Mult False: used for single user
  3. Type User - Mult True: used for multiple users too
<Field
       ID="{c55e296e-e0bf-4574-b266-a421781b5081}"
       Name="Approvers"
       DisplayName="Approvers"
       Type="UserMulti"
       Required="FALSE"
       Group="VLibs SP2013 Examples site columns"
       EnforceUniqueValues="FALSE"
       UserSelectionMode="PeopleOnly"
       UserSelectionScope="0"
       Mult="TRUE"
       Sortable="FALSE"/> 
<Field
       ID="{C4AC8A6C-F65C-4BC1-BE36-F83919EE9886}"
       Name="ItemUser"
       DisplayName="Type User - Mult False"
       Type="User"
       Required="FALSE"
       Group="VLibs SP2013 Examples site columns"
       EnforceUniqueValues="FALSE"
       UserSelectionMode="PeopleOnly"
       UserSelectionScope="0"
       Mult="FALSE"
       Sortable="FALSE"
       Overwrite="TRUE"/> 
<Field
       ID="{9af230e5-cdff-40ac-ae13-f2a6928dd1d1}"
       Name="ItemUsers"
       DisplayName="Type User - Mult True"
       Type="User"
       Required="FALSE"
       Group="VLibs SP2013 Examples site columns"
       EnforceUniqueValues="FALSE"
       UserSelectionMode="PeopleOnly"
       UserSelectionScope="0"
       Mult="TRUE"
       Sortable="FALSE"
       Overwrite="TRUE"/>
Workflow
 I have created a stupid workflow (named stupid workflow for real) which prints fields value in history
i added this item to the list, launched the workflow
 
and this was the result

As you can see, for the first field i obtained a list of user id, for the second field a single id: those int numbers can be used to make a user lookup, but what about the third field?

Resolution
For this particular example you need a custom activity in order to read the field value from results property in a collection string object.
This custom activity needs as input value, the user field dynamic value, and a collection string variable to save che user ids.

  
Placing the activity and configuring the output was this.
To play with this workflow and custom activity, you have to download latest version of VLibs from here, and enable features 01, 07a and 07b. Have fun.
written in: Milano, Italia

0 commenti:

Post a Comment

Because of a lot of SPAM about courses, I need to moderate all comments here.
I ensure you that I will answer whenever possible (if you are not a spammer).

Me, myself and I

My Photo
I'm just another IT guy sharing his knowledge with all of you out there.
Wanna know more?