Error operating on collection variable, advice on date triggered alerts

  • 16 November 2020
  • 11 replies
  • 17 views

Badge +5

Afternoon

 

I have a workflow that I want to loop through a list every day, store start dates, then later in the flow fire off alerts if today's date is one month, three months, or six months on from that initial start date.

 

I've set up a flow which adds the required dates to a 'Today's Date' variable, then runs and alert if the start dates equals the variable. That works fine, it's the scheduled For Each and Collection Operation I'm struggling with.

Here's how I've configured the 'For Each':

9466i645FC26DE9719980.png

 

and here's the Collection Operation:

9467i2F72B10415C10583.png

I'm getting 'Error operating on collection variable. Index property is greater than the number of items in the collection.' when the flow hits the Collection Operation. What's the best way to proceed? All help appreciated!

 

 


11 replies

Badge +6

Hi.

 

Could you explain why you are using the Collection operation to do the same thing that is accomplished in the For each?  Both are setting Two_weeks_dates to the current item in the collection.

 

Also, is the Collection operation contained within the For each loop?

Badge +5

Thanks @ethurber thought I needed Collection Operation to store the information from the list? So I could just do a For Each and store in a Collection variable then use that to do the comparison in the Run IF action?

Badge +6

Hi.

No.  The for-each loops through the collection and stores each entry in the variable specified (not a collection variable).  From what i can tell from your screenshot, you have the for-each configured properly.  From that point, you can process that variable any way you want.  Just be sure that all of the processing is in the for-each loop.  When the processing is complete for that item, it will return to the top of the for-each and pull the next item from the collection and store it in the variable.  It will repeat until all items in the collection are processed.

I hope this wasn't more information than you needed.

Ed

Badge +5

Thanks @ethurber that's really helpful.

 

So I want to store the user name and start date then have actions fire if the start date = the start date + three months. I have a query list action which is returning all the users names and start dates. What's the best way to store these variables so that I can do the comparison and trigger the actions?

This is how the For Each is configured:

9489i9D27D63B6FF2805A.png
and here's the flow as it stands:

9490i3969A1E1D210EDE8.png

 

Thanks for all your help!

Badge +6

Hi.

This is what came up with based on my understanding of your requirements.  It's a site workflow that is scheduled to run daily.  I'm assuming that you wanted to send an email to the employee (i can't read the label on you send email action)

9500iDCDB3C2F74B4B871.png

9495iDBE7D3697FE955F2.png

The query list action

9496i8B668738CD025DC1.png

For each action

9497iCD85997BBB35DAEC.png

Run if action

9498i839BF6AC581779E2.png

Collection operation

9499i23207C3195F9DB8C.png

Hope this helps.

Badge +5
Thanks @ethurber I'll give that a go!
Badge +5

@ethurber  how would I configure the Calculate cut-off-date action? I'd need it to be the Start Date plus 30 days and then store it in the datCutOffDate variable in your example?

Badge +6

The cutoff date is the current date - 90 days.  This is used to filter the query because you are not interested in any dates older than 90 days.

Badge +5

Thank you so much for your help @ethurber  . I'm a still a little confused by the cutoff date. For example I need the alerts to fire if the employee is one month on from their start date. So if their start date was the 16th I'd need it to fire send an alert on the 16th of December. So would I not get their start date then add a month in the Calculate Date and then would I need to filter the results later?

 

Thanks again!

Badge +6

Hi @Sutekh.

The cutoff date is the current date - 90 days.  It is only used to filter the query.  Rather than read in the entire list, you are only interested in those employees who were hired within the past 90 days.  You will get everyone that was hired within the past 90 days, but the ones you don't want get filtered out here. 

9508i13CF914657480647.png

the 3 calculate date actions take the start date of the current collection entry in the for-each loop, and add 30, 60, and 90 days respectively.

9509i424FD46E9C638DA7.png9510i317D50C18681B6C2.png9511i2B5502B30D4C1884.png

Note that each action stores the resulting date in a different variable.

 

The run-if compares each of those variables with the current date.

9512i4667261E0F024C28.png

if 1 of those dates is the current date then the email is sent.  If none of the dates are the current date, then it is skipped, the flow returns to the top of the for-each, and the process repeats with the next start date in the collection.

 

Hope this helps

Badge +5

Hi @ethurber  I think I'm getting closer! I ran the flow and the Run Ifs aren't firing any alerts so I put an alert in to myself to see what the variables were returning. I got hundred of emails as it's returning the start dates of the staff and adding the additional time

 

 

One month: 14/10/2020 00:00
Three months: 29/07/2018 00:00
Six months: 29/10/2018 00:00

datStartDate  datStartDate
 
Today: 01/01/1900 00:00


CollectionStartdate: 14/10/2020 00:00:00;22/10/2020 00:00:00;04/10/2020 00:00:00;06/10/202000:00:00;04/06/2020

 

So the datStartDate Date variable isn't returning a result and I'm trying to use that in the Run IF


9529i6B685FEE460BED8C.png

 

Here's how I've configured the For Each action:

9530i87FED2522D46B2D9.png

Really appreciate your help! Where am I going wrong?

 

Reply