cancel
Showing results for 
Search instead for 
Did you mean: 
lgiambar
Nintex Newbie

Query a list to see if a value in a collection variable exists

I have two lists that I am working with. The main one has my Nintex form on it. The form has multiple people picker fields on it. What I need to do is after the form is submitted, I need to see if the people entered on the form exist in a secondary list, if they are not there already, they need to be added, if they are there, then do nothing. 

I was trying to push all of the names into a collection variable and then query the secondary list to see if any of the names from the collection exist on the list but I can not figure out how to make this work.

Any ideas?


Thanks! 

Reply
5 Replies
courtney_shelto
Nintex Newbie

Re: Query a list to see if a value in a collection variable exists

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!

0 Kudos
Reply
lgiambar
Nintex Newbie

Re: Query a list to see if a value in a collection variable exists

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!! 

0 Kudos
Reply
courtney_shelto
Nintex Newbie

Re: Query a list to see if a value in a collection variable exists

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!  

0 Kudos
Reply
lakshminarayana
Nintex Newbie

Re: Query a list to see if a value in a collection variable 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,

0 Kudos
Reply
emha
Nintex Newbie

Re: Query a list to see if a value in a collection variable exists

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.

0 Kudos
Reply