5

Using a workflow (and anything else Middle Tier including scripting), can you remove a single name from a multiple-user Person or Groups field?

I'm toying with the idea of a "subscription" model:

  • User Selects "Subscribe Button"
  • User is directed to workflow initiation form - checks box
  • Workflow creates entry in a list with Created By
  • Workflow takes Created By and adds it to a Multi-User People/Groups Field (By creating string "{Multi People Field}; {Created By}"
  • When new items are added to a particular folder in a discussion list, a workflow sends the new content in a nicely-formatted e-mail to Multi-User People/Groups Field (turning that field into a workflow variable that let's Designer send the e-mail)

Great. Using some other workflow magic, I could display, in this particular discussion folder, who is currently subscribed and therefore how many subscriptions and use popularity to rank discussions...etc. And I know multi-user People/Groups fields eventually have a limit - I think that's solveable. I think you can even mess with the XML of the workflow file to BCC the listing of people.

None of this is worthwhile, however, unless a person can easily remove him/herself from that multi-user People/Groups field. An "Unsubscribe" process, if you will.

  • Actually...in this case, my users who would subscribe to an item each exist as a unique item in a list. If that list captures "preferred e-mail" and a calculated column adds a space before the value, I could maybe have a lookup from the target list - so e-mails would go to a string value like "Lastname1, firstname1; lastname2, firstname2" - now I just need to find a way to filter the multi lookup field based on current user. – Cory M Mar 29 '12 at 17:55
0

This is very difficult to do in SPD2010 Workflows because that platform has no native actions for working with arrays or Dictionaries (if I am wrong please let me know). That said, I haven't tried it but I think it would be much easier to do this in an SPD2013 workflow, since you could get the multi-value person field as a dictionary and loop through it pretty easily.

It's doubly unfortunate that Microsoft did not provide any actions to manipulate strings or arrays in SP2010 workflows, since those kinds of operations are trivial in every programming language.

In any case, I was able to remove a single user from a multi-value person field in an SP2010 workflow by using a series of Array and String actions, as provided by the 3rd-party HarePoint Workflow Extension product. (Disclaimer: the sets of Array and String actions provided by HarePoint are free to use, but I am not myself affiliated with the company.)

So, broadly, here are the steps. We are going to split apart the field value, remove the value we don't want, join it together again, and set that as the new value of the field.

Steps

  1. Get the multi-value Person field as a string of semicolon-delimited User Ids User Ids, Semicolon Delimited
  2. Get the User Id you want to remove as a string Get the user id Return the person value as a user id
  3. Split the multi-value person field string variable by ; (semicolon). This produces an array of integers as strings. Split the field value by semicolon
  4. Find the index of the item you want to remove Find the index of the item you want to remove
  5. Remove the desired User Id from the array. (You should also include a conditional statement to check that the index is greater than -1, to handle cases where the target user id is not found in the array. Remove the desired user id from the array
  6. Join the array back together with ; (semicolon) as the delimiter. This gives us a properly-formatted string. Join the array together again
  7. Update the multi-value field by setting it to the joined string Set the field value from the joined string

Success! Now the field is less one person.

Below is a screenshot of the whole process in development. This works for me, but your mileage may vary.

enter image description here

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.