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 replace space in the business duration value & replace it with :

SAS21
Tera Guru

calculating the pending duration for an Incident (Pending Start Date, Current date)

eg: Its giving me the value as 1 04:45:47  (days  hr:mm:ss)

 

I have to replace the space (which is next to days) with a : and pass the entire value as 1:04:45:47 in a function 

 

How do we replace a space with colon and pass the entire value in the above format ? 

 

Thank you

Bhavana

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@SAS21 

after doing the calculation where do you wish to store it? is it in some duration field or string?

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

Hi Ankur, 

 

This is how i am doing it. Pls check

var currentDate = new GlideDateTime();
var gr = new GlideRecord('u__incident');
gr.addEncodedQuery('u_status=Pending');
gr.query();
while (gr.next()) {
  var pendDays;
   var pend_dur;
  var pendStartDate = gr.u_pend_start_date;
pend_dur = utils.getBusinessDaysDuration(pendStartDate, currentDate);
// o/p - pending duration1 04:45:47
   gs.info('pending duration' + pend_dur);

pend_dur.replace(' ', ':');

gs.info('pending duration after ' + pend_dur);

//o/p - pending duration after 1 06:45:32

}
 
Its printing the same like before