Help with workflow waiting for date to be reached

Blair5
Tera Guru

I'm having some difficultly with what solution to use for following requirement:

User fills out catalog form and chooses a date. Another date is auto-populated with date 8 months in the future. Once submitted and tasks completed, there should be a timer or a wait activity (??) that will send an email 2 weeks before date is met (and again 1 week before date). 

Not sure how to do this - I set a timer and added this code. But does it keep checking? : 

var difSeconds = gs.dateDiff(gs.nowDateTime(), current.variables.return_date.getDisplayValue(), true); 

gs.log('seconds: '+difSeconds);


if(difSeconds == 1209600){
	answer = true;
}
1 ACCEPTED SOLUTION

DirkRedeker
Mega Sage

Hi

There was a similar question recently, which I answered in detail at the following URL:

https://community.servicenow.com/community?id=community_question&sys_id=1f8449aadb1adc5066f1d9d96896...

This is using the Workflow and is quite simple to achieve. You can just give it a shot, instead of writing your Scheduler.

Let me know if that answers your question and mark my answer as correct and helpful.

Enjoy & BR

Dirk

 

 

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Blair Reinhart 

You can easily use flow designer to achieve this

but if you wish to use workflow then below should help

when the OOB answer variable becomes 0 it will proceed; till that time it will always calculate

please use this script in timer script to wait for 2 weeks

var gdt = new GlideDateTime(current.variables.return_date);

gdt.addDaysUTC(-14); // 14 days

answer = gs.dateDiff(new GlideDateTime(), gdt, true); 

please use this script in timer script to wait for 1 week

var gdt = new GlideDateTime(current.variables.return_date);

gdt.addDaysUTC(-7); // 7 days

answer = gs.dateDiff(new GlideDateTime(), gdt, true); 

Flow Designer:

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur - Thank you.

I think I may take a different approach to this. Instead of leaving a workflow open for minimum of 8 months, I may close the workflow, run a job and when dates meet criteria, send emails. Once date equals current date, generate a new workflow to complete work. 

Hi,

Just to inform the job will be running daily at particular time and checking for the required condition.

Another approach would be using BR, event and script action approach. The event will be scheduled and processed 2 weeks before the date.

Let me know if that answered your question.

If so, please mark response as correct & helpful

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank you for the suggestions ... definitely need to think about this. Thanks again