I have to check a field is updated on within 5 months.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2023 02:51 AM - edited 06-22-2023 02:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2023 05:29 AM
you cannot check this unless the table is audited.
If the table is audited you can check the audit table for the same
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2023 07:06 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2023 08:02 AM
yes with that it will work.
It's just that you need to keep that field updated everytime the field changes
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2023 05:31 AM
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.