Solved

Send email to each user using For Each Loop


Badge +11

Hi

 

The purpose is to send an email to each requester.
I have used a QueryList to store the [IDs] into a collection = col_IDs

Now, at the For Each, I set as following;

Target collection:  col_IDs

Store result in: txt_IDs

 

Then, I added the email to say send to Requester.
But it does only send out to the 1st and same requster!

How, do I make it so it loops for each ID in the collection and then sends email to the relevant Requester of each Item with the Ref Number, etc.? 

 

 

icon

Best answer by bimi82 22 June 2021, 12:06

View original

15 replies

Badge +12

@bimi82  try below approach:


 



  1. Using Query List select IDs, Requestor & Ref. #. and store all of them in the collection variables

  2. Using For Loop action, ID Collection and number variable (to store index value)

    1. Add Parallel action for each remaining collections

      1. Using collection operation and index value, get respective values



    2. Add Commit pending changes

    3. Add email notification and configure your email




 


Alternate approach is:


 



  1. Get only ID collections using query list

  2. Using For Loop and ID Collection:

    1. Add Run Parallel action and in each branch use Set Variable action. You need to use list lookup option, select your list and ID column. Compare it with the variable you got from for loop

    2. Add Commit Pending Changes

    3. Configure email



Badge +11

Hello @kunalpatel 


 


Would appreciate if you could visuliase it, it's easier for me to understand.
Here is what I have done so far:


 



Now, in the For Each loop:



I am unsure what the INDEX does, and how to put it in action?

This is how it looks:



By this, it sends out 2 emails (because atm. there are only 2 entries)
and the emails are send to each Requester.

Now, what if I wanted to include the Reference number and anything else from each item?
Logically, it should look at the ID of the item and then allow me to pick anything from it.

If could send screenshots would be great.


 

Badge +11

I think I managed to get it done:
This is the workflow:




1) the Query List, stores the IDs into a collection = col_IDs
2) the For Each looks at the col_IDs and stors result into txt_ID
3) the Qeury Lis (within the Loop) filters where the ID is equals to txt_ID
4) store the prefered information into variables


5) send an email with the information out.


 

Badge +12

@bimi82 your workflow is querying the list on each item. Instead of putting the load on the system you can easily achieve the same results by collection variable and index variable.

Badge +11

@kunalpatel can you explain how to achieve that?
Please do a step by step with screenshots...

cheers

Badge +12

@bimi82 in your post where you queried your list and got IDs and Created By collections, make following changes:


 



  • In For Loop instead of Created By's collection, use ID collection

  • Created a number variable i.e. num_Index and add that in screenshot # 2 i.e. the one in For Loop

  • Inside For Loop, add a collection operations and use Created By's collection in here and get the value for num_Index 

Badge +11

@kunalpatel 


I am slightly confused because the Index won;t allow me to select any variables!
Anyway, this is what I done so far:

In the QUERY LIST:



 


In the For Each Loop:



I am not able to set the Index to any variables.
Normally it is an Interger and it does not work ... I tried with all.


Then you suggest to add a Collection Operation within the for each loop, like this?



How do I specify what GET information I want?
Because the Index would have an array of information.

Ideally I would want to say : for each item, get me the name/surname/email etc. etc.





 


 

Badge +12

@bimi82 your index variable is integer...it needs to be number type. See below screenshots


 



 



 



 

Badge +11

@kunalpatel and this approach does not use much resource, you saying?
Whereas in my solution, the query runs for each item and if there is many items then it will cause too much resource? is that what you are saying?

On other hand, when storing the output into variables and use Collection Operation then it will simply fetch the Data from the Num_Index - that is how I understand your solution.

Badge +12

@bimi82 that's correct. In my approach you query the list only once and store values you need in collection and then you manipulate collection variables to get what you need. 


 


In your solution, you first query the list and then inside for loop you query the same list multiple times.

Badge +11

@kunalpatel hmm intresting and is there a statement from Nintex to confirm your statement?

As per your solution: imagine if I had 20 variables holding information then I would need 20 x collection operation to get the result from the num_index??

Badge +12

@bimi82 ...you can either open a case with Nintex support or do some research but the reason I gave is my understanding on how each action works. Each time you run query list that means based on the parameter you've provided in the action it's going to query the SQL table to get the information, so do your math, querying SQL once will use more resource or querying same table multiple times ?


 


Also yes, you'll have to create the 40 variables (20 for collections and 20 for storing individual values). If you think spending time in creating these variables weighs less than querying SQL multiple times then please create the solution which you think best. 


 


If I've to create this solution then I'll go with collection variables, I'll put these collection operations in an action set or run parallel and collapse the action. Also before entering to next action, I'll put commit pending changes, just to make sure each collection operations have been completed.

hey! I know it's been a long time, but is there any chance you have screenshots of the configurations within the steps? trying to do something similar and I feel like i'm very close but would love to see within each of the steps. thanks!

Badge +12

@tim121 what exactly you're trying to achieve? I don't have any test workflows on hand and I cannot share my PROD workflows either.

@kunalpatel @bimi82 So i'm attempting to send an email to each of the email addresses in a list that I maintain. For some reason I can't get the loop to run through and grab all the addresses to store into a collection variable to be used in the "send notification" action. I was looking to see whether the OP had the details within each of the actions to see what variables go where. thanks!

Reply