I have to check a field is updated on within 5 months.

abhisek
Tera Contributor

There is a field. I have to check that field is last updated on within 5 months using script.

 

Can anyone please help me out.

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@abhisek  

you cannot check this unless the table is audited.

If the table is audited you can check the audit table for the same

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

Hi @Ankur Bawiskar 

 

Can we do it by creating another date field which filed will capture the date when that other date field was updated on last time? If yes, then could you please let me know the logic behind that.

 

Thanks in advance.

 

Regards,

Abhisek Chattaraj.

@abhisek  

yes with that it will work.

It's just that you need to keep that field updated everytime the field changes

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

Kalyani Jangam1
Mega Sage
Mega Sage

Hi @abhisek  

Please try below script

 

var gr=new GlideRecord("sys_history_line"); // GlideRecord in History table
gr.addQuery("field","hold_reason"); // Value of your field
gr.query();
if(gr.next()){
gs.info("Updated time-----"+gr.update_time); // Updated time means field when last updated
var gDate = new GlideDate();
gDate.setValue(gr.update_time);
gDate.addMonthsLocalTime(-5);
gs.info(gDate)
if(gr.update_time <= gDate){
gs.info("In 5 Month ago");   // last updated before 5 month
}else{
gs.info("Greater than 5 Month ago");
}
}

 

Please check and mark helpful or correct if it works for you.