bimi82
Contributor

Send email to each user using For Each Loop

Jump to solution

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.? 

 

 

0 Kudos
Reply
12 Replies
kunalpatel
Collaborator

Re: Send email to each user using For Each Loop

Jump to solution

@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
0 Kudos
Reply
bimi82
Contributor

Re: Send email to each user using For Each Loop

Jump to solution

Hello @kunalpatel 

 

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

 

bimi82_0-1624307738296.png

Now, in the For Each loop:

bimi82_1-1624307826370.png

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

This is how it looks:

bimi82_2-1624307909118.png

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.

 

0 Kudos
Reply
bimi82
Contributor

Re: Send email to each user using For Each Loop

Jump to solution

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

bimi82_0-1624356212924.png


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.

 

View solution in original post

0 Kudos
Reply
kunalpatel
Collaborator

Re: Send email to each user using For Each Loop

Jump to solution

@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.

0 Kudos
Reply
bimi82
Contributor

Re: Send email to each user using For Each Loop

Jump to solution

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

cheers

0 Kudos
Reply
kunalpatel
Collaborator

Re: Send email to each user using For Each Loop

Jump to solution

@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 
0 Kudos
Reply
bimi82
Contributor

Re: Send email to each user using For Each Loop

Jump to solution

@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:

bimi82_0-1624517707250.png

 

In the For Each Loop:

bimi82_1-1624517741569.png

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?

bimi82_2-1624517866428.png

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.



 

 

0 Kudos
Reply
kunalpatel
Collaborator

Re: Send email to each user using For Each Loop

Jump to solution

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

 

02_QL.jpg

 

03_For_Loop.jpg

 

04_Collec_Ops_For_Requestor.jpg

 

0 Kudos
Reply
bimi82
Contributor

Re: Send email to each user using For Each Loop

Jump to solution

@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.

0 Kudos
Reply