Duration Type field auto conversion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 03:36 AM
Hi All,
We have duration type field on the form , and if the user enters more than 24 hours in the hours field it automatically converts to 1 day , for example : "Days 00 Hours 25 Minutes 00 Seconds 00" now if I save the record it would automatically convert to "Days 01 Hours 01 Minutes 00 Seconds 00".
My requirement is that if user enters more than 8 hours under hours field it should throw an error saying please enter hours less than or equal to 8.
But whenever I tried to obtain the value of the field it always converts the hours to equivalent number of days if hours are entered greater than 24. I tried in both from front end in Client Script and backend in Business Rule as well.
Any ideas on how to get around this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 03:50 AM - edited 02-17-2025 04:00 AM
can you try this?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var duration = g_form.getValue('duration'); // Replace 'duration' with your field name
var durationParts = duration.split(' ');
var days = parseInt(durationParts[0].replace('Days', '').trim());
var hours = parseInt(durationParts[1].replace('Hours', '').trim());
if (hours >8) {
g_form.showFieldMsg('duration', 'Please enter hours less than or equal to 8.', 'error');
g_form.clearValue('duration');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 03:59 AM
This is not going to help because whenever the user will enter more than 25 hours in hours field it will automatically get converted to 1day 1hour and this is how I will receive the value so I will never know how many hours the user enters because the user can enter days as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 04:03 AM
Since you have not got any solution yet, please don't mark any response as correct as other members won't be able to help if they see it as answered
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 04:03 AM
then it would be difficult to determine.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader