scheduled job to make active field false by comparing dates

Asif_Jawed
Tera Expert

I need to create a schedule job for custom table which will run every day. The Schedule job will compare current datetime field with custom date field and if that date matches, make active false. I have written the code below. It is not working.

 

AsifJawed1_0-1696843206669.png

 

6 REPLIES 6

Hugo Gomes
Kilo Guru

You just need to do the following to compare the dates:

var diff = gs.dateDiff(gs.nowDateTime(), gr.u_talent_pool_expiry_date, true);
 
if(diff < 0){ //checks if the date inserted has already expired
//do your logic here
}

Manoj89
Giga Sage

Hi Asif,

 

You can try this

var gr_inc = new GlideRecord('incident');
gr_inc.get('0488459f476135108b8dfa37536d434a');

var resolved = new GlideDateTime(gr_inc.resolved_at); //2023-10-09 22:37:31
var dateTest = new GlideDate();
dateTest.setDisplayValue(gr_inc.u_date_test); //2023-10-08

var duration1 = GlideDate.subtract(dateTest, resolved.getDate());
gs.print(duration1.getNumericValue()/(60*1000*60*24));

The result I got in the Background script

Manoj89_0-1696866190585.png