- 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-26-2023 05:50 AM
why both the times are 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
10-26-2023 05:57 AM
Here my requirement is to configure logic to calculate 24 hours of time after pin generation. if 24hours is passed then pin expired should be true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 06:02 AM
I am asking why both the values i.e. now time and the pin time are 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
10-26-2023 06:10 AM
for testing purpose i updated the pin generation, as in wneh to run we kept insert and update, hence both took same time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 06:25 AM
so basically you want if the pin generation time is older than 1 day then mark the flow as true
For this you need to have flow which runs daily and checks this in condition and then update the flag
BR will run only when some update etc is done
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader