Sending email alerts when after 7 days have elapsed on list items

  • 16 November 2017
  • 25 replies
  • 28 views

Badge +10

I have a Form Library for new starters. One of the InfoPath fields is Start Date. What I want to happen is that after seven days has elapsed after the input start date that the initiator gets an email to remind them.

I've set up a Caculate date action as below. dt_Today is a Date and Time variable, dt_NotificationDate is also a Date and Time variable

Calculate date

Next I have a Build String action to format the date and store it in txt_TodaysDate which is a Single line of text

Next I have Query List action. The Coll_IDs variable is a List Item ID variable


Next I have a Loop action.  The CollecetedHRDates is a collection variable, the varCurrTitle is a single line of text variable and idx is a number.

 

This is where I come a cropper. I've got a Collection operation Action

When I run the Workflow and look at the Workflow Progress it carries out the For Each action, but doesn't action the Collection operation and the subsequent Send Notification action.

I've set up two Log in history list actions and I'm getting results for dt_Today, dt_NotificationDate and txt_TodayDate but not Coll_IDs.

Any suggestions on why it's not executing the Collection operation and subsequently not sending the notification?


25 replies

Userlevel 5
Badge +14

so, let's go step by step

Next I have a Build String action to format the date and store it in txt_TodaysDate which is a Single line of text

nothing wrong with this action, however, if you stored result of previous calculate date action as ISO date string to a text variable you would basically get the same output and you might have saved one action.

Next I have Query List action. The Coll_IDs variable is a List Item ID variable

if a variable where you store result set of query list action is of type 'List Item ID' or any other scalar type (single line text, number,...) you will only capture first value returned by the query. all the others will be ignored.

change the type of Coll_IDs variable to collection!

if  you add another list fields to be returned by query list action, each of them have to be stored to a separate collection variable.

Next I have a Loop action.  The CollecetedHRDates is a collection variable, the varCurrTitle is a single line of text variable and idx is a number.

you have used here not initialized, empty collection variable CollecetedHRDates to loop through.

since it is empty the workflow will not step into the loop and no action within the loop will be executed.

you should have used here a collection variable that you previously populated with query list action - ie. Coll_IDs collection variable should have been used in place of CollecetedHRDates 

you have used varCurrTitle variable of type single line text to store current collection element to.

the data type is correct.

the name doesn't play a role from functionality point of view, but since it will hold an item ID retrieved from Coll_IDs collection at current index position (driven by for each loop action), the much more suitable name could be like varCurrID.

This is where I come a cropper. I've got a Collection operation Action

this action is not needed (for the moment). you only query for one single list field (ID) with query list action, so you have only  one collection returned (collection of IDs). For each loop action iterates over this collection and retrieves current collection element value (one item ID) and saves it to text variable as explained above.

for the moment you do not have any other collection variable which you would need to retrieve values from.

you might need the action, if you queried for more then one list field in query list action.

Badge +10

Thanks Marian. I think the finish line is almost within sight!

 

I've set up a collection variable called Coll_IDs_2. Happily it's running through the entire Workflow, but is only giving me one alert which is pretty blank, details below:

Badge +10

The varrCurrID is a Liste Item ID

Userlevel 5
Badge +14

so you got returned one item from query list action with ID=33 (content of  Coll_IDs_2).

since the collection had one element, one loop iteration was executed and you got notification. so the workflow basically works.

I'm not sure about content of your other variables/references.

Badge +2

As Marian already mentioned that your list item id is Coll_IDs_2.

Regarding your other fields - I think you have to check whether this fields into your form is blank or not? If not blank then you have to re-configured the fields into your email body. Also make sure that you have choose proper fields value from library only.

Badge +10

Thanks ‌ . I need the workflow to send emails for every item which hits the 7 day elapsed date, but all I'm getting is an alert for Pertwee, and I've entered items with a start date that should trigger an email but all I'm getting is the one for Pertwee.I've logged the Start Date to the history list and had it output to the email and it's giving today's date, surely it should be 13/11/17 ? And shouldn't I be getting alerts for more items eg Ainley?

Userlevel 5
Badge +14

Please post configuration of query list,for each loop and send notification actions that gave you this results.

Post as well value of variable from query list action  (likely txt_TodayDate from above)

Badge +10

I ran the workflow and got:

{WorkflowVariable:dt_Today}  01/01/1900 00:00

{WorkflowVariable:dt_NotificationDate} 08/01/1900 00:00

{WorkflowVariable:txt_TodayDate} 1900-01-08

then I ran it again and got:

{WorkflowVariable:dt_Today} 17/11/2017 08:25

{WorkflowVariable:dt_NotificationDate} 24/11/2017 08:25

{WorkflowVariable:txt_TodayDate}  2017-11-24

Here's the configs:

Userlevel 5
Badge +14

This should have returned an item for Hartnell.

That's only item with StartDate==24/11/2017

Badge +10

How would I get email alerts for any item after 7 days elapsed? So any item entered with a Start Date of the 10th of Nov

Userlevel 5
Badge +14

In calculate date action change Days to add value from 7 to -7

Badge +10

Thanks Marian, I've tried that and it's only giving me alerts for Hartnell, shouldn't I get alerts for Baker and Pertwee as well?

Userlevel 5
Badge +14

Pertwee should be selected as well, but Baker not - he doesn't have StartDate 10/11/2017

Badge +10

I added a few starters with the 10/11/2017 start date and inexplicably got three alerts for Hartnell! They all had a start date of 01/01/1900 00:00

Userlevel 5
Badge +14

that means query list action correctly returns 3 items.

but you likely have somehow wrong configured notification action or do not correctly populate variables used in notification.

do you have notification inside the loop?

Badge +10

Hi Marian

Yes the notification is in the loop:

The variables in the notification are newstartername (single line of text) and startdate (date and time). The only alert I'm getting is for Hartnell which is the first item in the list.

Userlevel 5
Badge +14

but item IDs should be correct within the notification, shouldn't they?

the problem is you do not initialize (scalar) variables used in notification anywhere.

as well, approach with independent query list actions is not very correct since between two list queries list content might change and you get inconsistent results.

use single query list action and configure it to return all the fields from list that you need to send in notification. save each returned field into different collection variable

eg. IDs, StartDates...

210860_pastedImage_1.png

then add collection operation into loop before send notification action and configure it to get collection element at the current index position from those added collections and save result to some single line text variable.

210861_pastedImage_2.png

then use the single line text variable (varCurrDate from above example) in notification

‌ multiple outcomes‌

Badge +10

Cheers. Are you saying use one Query List action to return multiple results? I didn't know you could do that. I'll take a look at that. I enabled the Collection operation as below

And I'm getting the following error:

'Error operating on collection variable. Index property is greater than the number of items in the collection.'

Userlevel 5
Badge +14

Are you saying use one Query List action to return multiple results?

yes, exactly.

I've posted you an example above.

'Error operating on collection variable. Index property is greater than the number of items in the collection.'

it's likely because CollectedHRDates is empty or contain different number of elements then the driving collection used in for each loop.

if you query all the fields with single collection, as advised above,  this will not appear anymore.

Badge +10

I think I'm almost there Marian Hatala‌!

So I'm just using the Col_IDs_2 collective variable and simplified the workflow just to the one Query List action as suggested. See below:

Query List

I've set up the Notification thus:

This is sending me three email alerts for William Hartnell. When I Log the Coll_IDs_2 variable in the history list it's giving me: {WorkflowVariable:Coll_IDs_2} - 39;47;48;  soooooo it appears to be getting the item but not the actual details of the item (the first/last name, department and stardate), so what do I need to do to get these details into the emails?

Userlevel 5
Badge +14

please read carefully my above hints and examples

use single query list action and configure it to return all the fields from list that you need to send in notification. save each returned field into different collection variable

then add collection operation into loop before send notification action and configure it to get collection element at the current index position from those added collections and save result to some single line text variable.

then use the single line text variable (varCurrDate from above example) in notification

you seem to store into collection just IDs.

all the other returned fields seem to be stored to some scalar variables (single line text?). that's the reason you get returned just first (single) department, manager,  startdate, etc.

Badge +10

Right, so the idea is that we're storing all the info returned in Collection variables to that they themselves can be collected together in the Collection operation action and referenced against the index? I've set up collection variables for all the queried fields. So (I'm sorry this is so painful Marian) in the Collection operation I should be able to add all the Collection variables in the Target collection drop down? It's only giving me the option for one collection?  

Userlevel 5
Badge +14

that's correct, collection operation can only work on one collection variable at a time.

you have to add as many collection operations into workflow as number of collection variables you want to read from.

you can put them one after the other in a sequence, like

210954_pastedImage_1.png

or if you want to make it a bit more effective you can use parallel action and read from each collection at the same time in parallel, like

210955_pastedImage_2.png

‌ get element‌

Badge +10

BOOM! That worked! Thanks for all your help ‌  couldn't have done it without you! The start date is coming out as 1/1/1900, lord knows why, but I'll figure it out. Thanks again.

Userlevel 5
Badge +14

GREAT!

what a success happy.png

please mark as answered former thread as well - Configuring a Workflow to send an alert when days have elapsed 

Reply