How to compare the date/time field with current date.

VIKAS MISHRA
Tera Contributor

I have a field on incident form named "follow up" this is a date and time field. 

I am creating on schedule job to perform the required action. which will run every morning 7 am.. 

As per the requirement if current date is greater then the date entered in the field "follow up" then it should change the incident state to "in progress". 

Could anyone please help me with the script.

 

1 ACCEPTED SOLUTION

Anirudh Pathak
Mega Sage

Hi @VIKAS MISHRA ,

Please try below code -

var currDate = gs.now();
var followDate = inc.u_follow_up; // Replace it with the correct object and field name

if(currDate > followDate) {
inc.state = '2'; // Replace it with correct object, field name and value
}

View solution in original post

2 REPLIES 2

Anirudh Pathak
Mega Sage

Hi @VIKAS MISHRA ,

Please try below code -

var currDate = gs.now();
var followDate = inc.u_follow_up; // Replace it with the correct object and field name

if(currDate > followDate) {
inc.state = '2'; // Replace it with correct object, field name and value
}

Dhananjay Pawar
Kilo Sage

Hi,

Try below code in scheduled job.

 

var upDate;
var curDate=gs.nowDateTime();
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
upDate=gr.sys_created_on;// here changer the field name.
if(curDate.toString() > upDate.toString()){
gr.state = '2';
gr.update();
}
else{
    }
}
Thanks,
Dhananjay.