- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 03:36 AM
Hi all,
The requirement is to check if the incident is created 4 hours, then update the incident's additional comment.
I've tried the following approach.
var dR = new GlideRecord('incident');
dR.addQuery('sys_id','57af7aec73d423002728660c4cf6a71c');
dR.query();
dR.query();
if(dR.next()){
var created = new GlideDateTime(dR.sys_created_on);
//gs.print("Created: "+created);
var gtime1 = created.getTime();
var created1 = gtime1.getByFormat('hh:mm:ss');
gs.print("CREATED ON (hh:mm:ss): " +created1);
var current = new GlideDateTime();
//gs.print("Current "+current);
var gtime1 = current.getTime();
var current1 = gtime1.getByFormat('hh:mm:ss');
gs.print("CURRENT IS (hh:mm:ss): "+current1)
var a = new GlideTime();
a.setValue("04:00:00");
created.add(a);
var b = created.getTime();
var c = b.getByFormat('hh:mm:ss');
gs.print("TOTAL: "+c);
}
if(c<current1)
{
gs.print('YES');
}
else
{
gs.print('NO');
}
Thanks & Regards,
Sreesh Surendran
ServiceNow Developer - Integrations & CSM.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 03:56 AM
Try
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', '57af7aec73d423002728660c4cf6a71c');
incidentGR.query();
if (incidentGR.next()) {
var createdTime = new GlideDateTime(incidentGR.sys_created_on);
gs.print("Incident Created On: " + createdTime);
var currentTime = new GlideDateTime();
gs.print("Current Time: " + currentTime);
var timeDifference = currentTime.getNumericValue() - createdTime.getNumericValue();
var hoursDifference = timeDifference / (1000 * 60 * 60); // Convert milliseconds to hours
gs.print("Time Difference (hours): " + hoursDifference);
if (hoursDifference >= 4) {
gs.print("Incident created 4 hours ago or more. Updating additional comments...");
// Your code to update additional comments goes here
} else {
gs.print("Incident created less than 4 hours ago.");
}
} else {
gs.print("Incident not found.");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 03:56 AM
Do it in a flow on incident creation: add a wait condition (and I hope some other logic) and add a comment to the incident after that condition. No need to script this.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 03:56 AM
Try
var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', '57af7aec73d423002728660c4cf6a71c');
incidentGR.query();
if (incidentGR.next()) {
var createdTime = new GlideDateTime(incidentGR.sys_created_on);
gs.print("Incident Created On: " + createdTime);
var currentTime = new GlideDateTime();
gs.print("Current Time: " + currentTime);
var timeDifference = currentTime.getNumericValue() - createdTime.getNumericValue();
var hoursDifference = timeDifference / (1000 * 60 * 60); // Convert milliseconds to hours
gs.print("Time Difference (hours): " + hoursDifference);
if (hoursDifference >= 4) {
gs.print("Incident created 4 hours ago or more. Updating additional comments...");
// Your code to update additional comments goes here
} else {
gs.print("Incident created less than 4 hours ago.");
}
} else {
gs.print("Incident not found.");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 10:25 AM
Thanks @Pratiksha - that worked.