Workflow set multiple people values to one Person column
Вопрос
I have a plain text field with Account Id's I'm trying to set a Person column with these values. I have a Visual Studio workflow doing this. I can insert 1 person but I can't seem to figure out the delimiter for multiple. I seen some things saying a comma will work but I'm getting an invalid look-up
error with this. And it can't be a semicolon due to the format the Person column expects (see below). Any help would be much appreciated.
String acctId = (String)workflowProperties.Item["Account Id"];
String[] stakeHolders = acctId.Split('\n');
String formattedStakeholders = "";
for (int i = 0; i < stakeHolders.Length; i++)
{
string delimiter = stakeHolders.Length > 1 && i < (stakeHolders.Length - 1) ? ", " : "";
//The Person column expects: -1;#DOMAIN\USERNAME
formattedStakeholders += "-1;#" + stakeHolders[i] + delimiter;
}
Решение
It needs a collection of users passed in, it can be done like so,
You can use the SPFieldUserValueCollection Class to set a multi value person field:
SPFieldUserValueCollection value = new SPFieldUserValueCollection(); value.Add(new SPFieldUserValue(web, user1.ID, user1.Name))); value.Add(new SPFieldUserValue(web, user2.ID, user2.Name)));
objItem["name"] = value; objItem.Update(); Where user1 and user2 represent SPUser objects.
If you just have the login names of the user accounts
Tip: To update a single value person field you can just set the user ID:
objItem["name"] = User.ID;
From https://stackoverflow.com/questions/8426660/how-to-insert-data-in-person-or-group-field-using-vs2010/8428774#8428774 also see http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/multiple-user-insertion-in-sharepoint-list/