add seconds and convert to date

radt
Kilo Guru

I have one duration field so I converted it to seconds using attribute  set to seconds. This value is milliseconds and so to get value I used:  (time_left is the duration field value)
var Duration = (current.time_left.getGlideObject().getNumericValue() / 1000); // multiple by .001 or divide by 1000


Now In duration I have days, hours, minutes in complete seconds .

 

 

So I have date field now which needs to be converted to seconds again: on_hold_till is the date field value

I have this code: 


var gdt = new GlideDateTime();
gdt.setValue(current.getValue('on_hold_till'));
var ms = gdt.getNumerciValue();

Now in var Duration I have duration in seconds and now in Var ms I have date field in seconds.

 

So now I have to add this and set this to a new field. ( I want duration to add to a date field to get a new date field):

like adding both this seconds and then converting totals seconds to a date field.

 

Any help on this!!!!! Please 

If you have easy way to add duration to date feel free to provide using the above field values.

 

TIA

 

1 ACCEPTED SOLUTION

Hi,

do this

// to get duration time to seconds.

var startTime = new GlideDateTime(current.u_date.getDisplayValue());
var duration = current.time_left.dateNumericValue();
startTime.add(duration);
current.u_target_date = startTime.getDate();

// OR if u_target_date is of type date/time then do this

current.u_target_date = startTime.getDisplayValue();

current.update();

Regards
Ankur

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

View solution in original post

12 REPLIES 12

The above BR is a different scenario and the one you help me and working is different. This BR is in scoped application and not working. as my previous BR worked when set to global so I tried this BR as well in Global but no use.

 

Breach Time is in SLA definition and target date is in case form .

 

 

radt
Kilo Guru

There is Rejection SLA 16 which is ==> and after that <==  What does that mean? 

 

This BR is not working but the code is perfectly fine. Is it due to this issue?

 

 

find_real_file.png

@radt 

Glad to know that my script worked.

Now you need to debug why that BR didn't trigger.

Did it satisfy the condition?

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

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