Ok, you're definitely on the right track! I would say get all your people in a collection variable. Then, do a "for each" and say, for each of these items, query list for an item where person == this person. Get a count. If count == 1, do nothing. If count == 0, then add this person (create new list entry).
So overall it will look like this:
This biggest thing to watch out for is how your people variables are formatted (make sure you're consistently using display name, or login name, or whatever).
Here's each action opened up:
I would also log a bunch of stuff, like your queryCountVar (make sure you list doesn't have duplicates, you could build in logic to help with that. Like using a switch instead of a conditional, and having queryCount ==1 do nothing, == 0 create person, and == anythingElse log it and email you, because that would mean there's a duplicate person in there).
Let me know if you have questions!
Thank you for the help. I have a couple of questions. First, it looks like you are using office 365? I have on prem, so my workflow actions look a little different. for example, my query list action does not have the option to have a separate output per column.
Also, is the variable you used in your filter section your collection variable?
Thanks!!
Oops! Sorry about that, how you have your query structured should be just fine.
I am not using the collection variable to sort. The "for each" output value I am using is simply text. So, if our collection was something like [Bill Rogers; Ricky Martin; Ozzy Osbourne] then on the first loop, that output value would be Bill Rogers, the second loop Ricky Martin, and the third Ozzy Osbourne. Hence, why we can look in your list to see if that person already exists!
Hi Leah Giambartolomei,
Can you try the following way.
1. 'Set Variable' - get field value (multiple person display names)
2. 'Regular Expression' - split multiple names with by a semicolon and store it in a collection variable.
3. 'Collection' action count operation - see single person or multiple persons store it in number variable.
4. 'Query List' - fetch 'List B' all items and store ids in a collection variable.
5. 'For Each' condition on List B items collection.
6. 'Set Variable' action - get display name of 'Person Field' from 'List B'.
7. 'Set a Condition' - to see the count from step 3.
8. Step 7: 'Yes' branch - check the value directly.
False means - use 'Update Item' action and do something.
9. Step 7: 'No' branch
9.1. 'For Each' action from collection in step 2.
9.2. 'Run If' action to check blank value.
9.3. 'Set a Condition' to check the value exists or not.
False means - use 'Update Item' action and do something.
Thanks,
what about to simplify it following way?
- make the list field unique (field's configuration setting)
- within workflow simply use create item in another site action to create new item without any former checks. configure error handling for the action. if an item doesn't exists yet, it is created and no error is reported. if it already exists, error is reported. based on the error flag you should be able to decide whether new item was created or not and proceed accordingly.