Workflow wait for specific time

sigmachiuta
Kilo Guru

I have a reminder date field on my form and I want to send out a notification when the time has elapsed (and set the state field to a new value) I have tried to add a timer in the workflow to

Timer based on: a date/time or duration field

field : u_reminder

wait: the full duration

But the workflow does not wait for the specified reminder date/time.   I have seen the below post but gs.eventQueueScheduled events are deleted after 7 days and you cant delete the event if the reminder date changes.   Also in the workflow if the user updates the date time after the execution will the workflow re-run?

Creating a Simple Reminder Email - ServiceNow Wiki

6 REPLIES 6

manikorada
ServiceNow Employee
ServiceNow Employee

Hi,



I have answered this question regarding the Timers in the post : Pending to Active state based on Due Date


Thanks Mani Kanta Korada , it looks like I can use the script from the post to check and see if the value of u_reminder changes and it will modify that field with the new value.   How can I have the workflow timer wait for the specified time to execute?



var wf =new Workflow().getRunningFlows(current);


var exeact = new GlideRecord('wf_executing');


exeact.addEncodedQuery('activity.activity_definition=3961a1da0a0a0b5c00ecd84822f70d85^context=' + wf.sys_id);


exeact.query();


if(exeact.next())


{


var trigger = new GlideRecord('sys_trigger');


trigger.addEncodedQuery('nameLIKE' + exeact.sys_id);


trigger.query();


if(trigger.next())


{


trigger.next_action = current.due_date;


trigger.update();


}


}


I started working on the workflow timer script to fire off when the time in the reminder field is the same as the current time set the state to active and allow the workflow to continue to fire a notification.   But this does not seem to work.



//Query any records in Awating user info and reminder is now


var gr = new GlideRecord('incident');


gr.addQuery('active', true);


gr.addQuery('state',4)


gr.addQuery('u_reminder', '=',gs.nowNoTZ());


gr.query();




while(gr.next()){




gr.state='1';


gr.update();


answer=true


}


Another issue I am having is that if the workflow has completed and the user changes the time/date field the workflow wont re set for the new time/date