How to send reminder notification before 30 days based on End Date

chanikya
Kilo Sage

Hi,

 

in catalog items, i have one filed, documents submit "Last  End Date"  (variable in catalog item)

ex: Last End Date=20/08/2018  19:50:20  then notification trigger one month before means on 20/07/2018.

So how can we do it.

my Br script is not working...

if(gs.dateDiff(gs.nowDateTime(), current.variables.ex_date.getDisplayValue(),true)/3600>=720)
{
var gdt = new GlideDateTime(current.variables.ex_date.getDisplayValue());
gdt.addDaysLocalTime(-30);
gs.eventQueueScheduled ( "thirty" , current, gs. getUserID ( ) , gs. getUserName ( ) , gdt) ;

}

1 ACCEPTED SOLUTION

Hi Chanikya,

You need to use your variable instead of my column name. Also I think you need to run this only for specific catalog item so if yes then add that query as well.

try this:

send1streminder();
function send1streminder() {
var task = new GlideRecord('sc_req_item');
task.addQuery('active', 'true');

var encodedQuery = task.variables.ex_date + 'RELATIVEGE@dayofweek@ahead@30^' + task.variables.ex_date + 'RELATIVELE@dayofweek@ahead@31';

task.addEncodedQuery(encodedQuery);
task.query();
while(task.next()){
gs.eventQueue('last_date', task, gs.getUserID(), gs.username());
}
}

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

20 REPLIES 20

is it right?? but it  is not working

 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('active',true);
gr.query();
while(gr.next()){
var datedif = gs.dateDiff(gr.variables.ex_date,gs.nowDateTime());
var datetrim=datedif;
var index=datedif.indexOf(' ');
var aftertrim=datetrim.substring(0,index);
gs.log('check date', aftertrim);
if(aftertrim =='30'){
gs.eventQueueScheduled ( "ex_date" , current, gs. getUserID ( ) , gs. getUserName ( )) ;
}


}

What log value you are getting?

find_real_file.png

Now it should run properly, also add the item sysid for which it should run

var gr = new GlideRecord('sc_req_item');
gr.addQuery('active',true); // also add the Item name for which it should run
gr.query();
while(gr.next()){
var datedif = gs.dateDiff(gs.nowDateTime(),gr.variables.ex_date);
var datetrim=datedif;
var index=datedif.indexOf(' ');
var aftertrim=datetrim.substring(0,index);
gs.log('check date', aftertrim);
if(aftertrim =='30'){ //It will check for end date is exact same as 30days
gs.eventQueueScheduled ( "ex_date" , current, gs. getUserID ( ) , gs. getUserName ( )) ;
}
}

i don't know why RITM number is not displaying, not only RITM number , short_description, item name

 

var gr = new GlideRecord('sc_req_item');
gr.addQuery('active',true);
gr.addQuery('cat_item','6b7ff7ae4f311300ab318df07310c7e6');// also add the Item name for which it should run
gr.query();
while(gr.next()){
var datedif = gs.dateDiff(gs.nowDateTime(),gr.variables.ex_date);
var datetrim=datedif;
var index=datedif.indexOf(' ');
var aftertrim=datetrim.substring(0,index);
gs.log('check date', aftertrim);
if(aftertrim =='30'){ //It will check for end date is exact same as 30days
gs.eventQueueScheduled ( "ex_date" , current, gs. getUserID ( ) , gs. getUserName ( )) ;
}
}