Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to access duration type field

Mark Wood
Tera Contributor

Hello Experts,

I have created a custom table for maintenance schedules. In the duration details section, my trigger type is set to "interval," and it repeats every 9 days. My requirement is to send a notification 3 days before each maintenance schedule. If it repeats every 6 days, the notification should still be sent 3 days before. I'm trying to access the "repeat" field value, whose data type is "duration," using the code below. However, I'm getting an output like "1970-01-10 00:00:00."

var gr=new GlideRecord('Demo_maintenance_schedule');

gr.get('5386d0941bb535d0a72cfdd2cd4bcba3');
gr.query();
if(gr.next())
{

gs.print('repeat'+gr.u_repeat);
}
2 REPLIES 2

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

The default value for duration field is  1/1/1970, That is the reason why you get those values as output.

 

Please check the below post it may help you out:-

 

https://www.servicenow.com/community/developer-forum/set-value-of-duration-field-via-business-rule/m...

Please mark my answer as correct based on Impact.

Amit Gujarathi
Giga Sage
Giga Sage

HI @Mark Wood ,
I trust you are doing great.
Please refer the below script

var gr = new GlideRecord('Demo_maintenance_schedule');

if (gr.get('5386d0941bb535d0a72cfdd2cd4bcba3')) {
    var repeatInSeconds = gr.u_repeat.getNumericValue(); // Get the value in seconds
    var repeatInDays = repeatInSeconds / (24 * 60 * 60); // Convert seconds to days

    gs.print('Repeat interval: ' + repeatInDays + ' days');
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi