How to send Notification based on the date on "record producer"

Prathamesh Cha1
Tera Contributor

Hi All,

 

I have a requirement where I want to send the notification before 2 weeks of the "expected target date" if the HR task called "Effective Date task" is incomplete, where "expected target date" is variable on record producer and "Effective Date task" is the task respective of HR case which is getting generated after submitting record producer.

 

I know values are stored in question_answer table but I don't understand how to implement this.

also using current.sys_id I can fetch table_sys_id in "question_answer" table and also sys_id of question will give me particular record and then I can fetch the value of variable "expected date"

 

But How Can I get sys_id of current record in scheduled job 

PrathameshCha1_0-1698658771161.png

 

3 REPLIES 3

Tai Vu
Kilo Patron
Kilo Patron

Hi @Prathamesh Cha1 

You can leverage the API below.

eventQueueScheduled(String name, Object instance, String parm1, String parm2, Object expiration)

 

Define your specific Event for the Notification. Then fire it using the eventQueueScheduled. Make sure to set to expiration param (Optional. GlideDateTime object or a date/time type element that specifies the date and time to process the event. Default: Current date/time)

Sample:

var processTime = new GlideDateTime(<expected_target_date>); //your expected target data
processTime. addWeeksUTC(-2); //before 2 weeks
gs.eventQueueScheduled('sn_app.user.deactivate', current, "", "", processTime);

 

Let me know if it works for you.

 

Cheers,

Tai Vu

Hi @Tai Vu ,

My expected target date changes when ever new record gets submitted, I want, it should work dynamically hence I want to use question answer table here to fetch expected target date then it should check everyday that if today is day of 2 weeks before the day of expected target day and if the mentioned task is not closed send notification.

Hi @Prathamesh Cha1 

So let's try this way.

1. In your scheduled job, query the active task records (not closed).

2. Check if the date before 2 weeks of the target date is before today.

3. Fire the event.

Sample below

var grTask = new GlideRecord('business_app_request'); //replace your table
grTask.addActiveQuery(); //replace your own conditions
grTask.query();
while(grTask.next()){
	var gdtTarget = new GlideDateTime(grTask.variables.arb_date); //replace your target date variable's name.
	gdtTarget.addWeeksUTC(-2);
	var gdtToday = new GlideDateTime();
	if(gdtTarget <= gdtToday){
		gs.eventQueue('<event_name>', grTask); //replace the event name
	}
}

 

Cheers,

Tai Vu