
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2020 11:02 PM
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 :-
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2020 01:03 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2020 10:10 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2021 11:47 PM
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