Can't find method com.glide.glideobject.GlideDateTime.subtract

srinidhi
Tera Guru

Hello All,

 

Am running the BR to check if the PIN generation time passed the 24hrs. Here is the below script.

 

but getting the error which i mentioned in the subject.
Please help on this.

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);

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@srinidhi 

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.

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

View solution in original post

22 REPLIES 22

Ankur Bawiskar
Tera Patron
Tera Patron

@srinidhi 

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.

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

Thanks Ankur, 

Am checking the script, will let you know.

 

srinidhi
Tera Guru

Thanks @Ankur Bawiskar , its working i accepted the solution.

my only concern is what will be the when to run condition?

 

@srinidhi 

it should be before insert/update and remove current.update()

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