How to convert integer value to Duration

Angshuman3
Mega Guru

Hi All,

I need to convert integer value into Duration format and capture it in a Field whose type is also Duration.

Scenario :

I have a catalog form, which has the below variables :- 
find_real_file.png

If any value is provided, in the 1st variable and the unit is selected, accordingly, we need to convert the value into a duration type (DD : HH : MM : SS) and return the same duration to another field placed out on sc_cat_item table.

Any leads, how we can get this done will be really helpful.

 

Thanks,
Angshuman

1 ACCEPTED SOLUTION

Hi,

try this

// do your calculation here and get milliseconds

var catItem = current.cat_item.getRefRecord();

var durationSelected = parseInt(current.variables.estimated_duration);
if(current.variables.unit == 'Hours'){
var hourConversion = parseInt(durationSelected*60*60*1000);

catItem.durationField.setDateNumericValue(hourConversion);

catItem.update();


Regards
Ankur

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

View solution in original post

16 REPLIES 16

Hi Ankur,

The issue was with the else block in the script. And, its resolved now.

Thanks for all the help, I am closing this thread though, but if I come across any issue further on this, I will reach out to you via this thread only.

Hope that's okay with you!

Thanks,
Angshuman

Hi,

I have a similar requirement here where I am trying to convert integer to duration but not able to achieve it. Could you please help me resolving this