- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 02:31 AM
Hello All,
Am running the BR to check if the PIN generation time passed the 24hrs. Here is the below script.
Thanks.
(function executeRule(current, previous /*, gs*/) {
var pingenerationtime = current.getValue('u_pin_generation'); // Get the PIN creation time
var currentTime = new GlideDateTime(); // Get the current time
var hoursElapsed = GlideDateTime.subtract(currentTime, pingenerationtime);
var diff = hoursElapsed.getNumericValue() / 3600;
// Check if 24 hours have passed
if (diff >= 24) {
current.pin_expired = true;// Mark the PIN as expired
current.update(); // Save the record
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 02:50 AM
use this
(function executeRule(current, previous /*, gs*/) {
var pingenerationtime = new GlideDateTime(current.getValue('u_pin_generation')); // Get the PIN creation time
var currentTime = new GlideDateTime(); // Get the current time
var dur = GlideDateTime.subtract(currentTime, pingenerationtime);
var diff = dur.getByFormat('HH');
// Check if 24 hours have passed
if (diff >= 24) {
current.pin_expired = true;// Mark the PIN as expired
current.update(); // Save the record
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 11:29 PM
Yeah @Ankur Bawiskar I tried but still not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 11:36 PM
please share latest BR script and configuration screenshpt
what debugging have you done so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2023 11:54 PM - edited 10-26-2023 02:26 AM
@Ankur Bawiskar Yes, please find the below screenshots.
Troubleshooting:
For testing purpose i have changed the time to 1hr.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 02:59 AM
are you sure you have given value in the pin generation field?
what field type it is?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 03:48 AM
yes @Ankur Bawiskar given, its date and time field.