0

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;
}
1

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/

  • 2
    It would have been great if there's a way to promot some people's comments as answers! – user19105 Feb 15 '15 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.