
- 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 12:39 AM
You can try another solution if it doesn't work then let me know, I will explain mine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2020 12:51 AM
Did you get a chance to check on approach suggested by me?
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 02:20 AM
It's better to have it in seconds if you are doing this level of calculation.
Try that script in "Run Script" activity.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2020 12:30 AM
Hi,
you are on workflow of RITM so you can do this
// do your calculation here and get milliseconds
var catItem = current.cat_item.getRefRecord();
catItem.durationField.setDateNumericValue(millisecondsValue);
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 12:51 AM
Hi Ankur,
I am trying the below script to convert the Hour value to Milliseconds, but, unable to get any retrieve any value.
var durationSelected = current.variables.estimated_duration;
if(current.variables.unit == 'Hours'){
var hourConversion = parseInt(durationSelected*60*60*1000);
}
when, I am putting logs for the hourConversion, I am not getting anything.