Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Duration Field

beycos
Tera Contributor

Hello Community, 

When I enter "24 hours" into a Duration field, the system automatically converts it and displays it as "1 day". However, I would like to see it displayed explicitly as "24 hours" instead of being normalized to "1 day".

Is there a way to prevent this automatic conversion or at least display the duration in an "hours" format (e.g., "24 hours") for the users?

Best Regards, 

Beyza 

 

5 REPLIES 5

Chaitanya ILCR
Mega Patron

Hi @beycos ,

you can use max_unit attribute and set it to hours max_unit=hours

ChaitanyaILCR_1-1747665062475.png

 

ChaitanyaILCR_0-1747665048664.png

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Thank you very much for your response. However, what I want to do is not to remove the "Day" field. I want to use the "Day" field only after 3 days. For up to 3 days, I want to use values like 24 hours and 48 hours. When I enter 48 hours, it converts it to 2 days.

@beycos 

not possible.

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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

Hi @beycos ,

not possible 

you can create a on load client script for form level

function onLoad() {
    var duration = g_form.getValue('duration');
    if (!duration) return;

    var parts = duration.split(' ');
    if (parts.length !== 2) return;

    var daypart = parseInt(parts[0]);
    var timeParts = parts[1].split(':');
    if (timeParts.length !== 3) return;

    var hours = parseInt(timeParts[0]);
    var minutes = timeParts[1];
    var seconds = timeParts[2];

    if (daypart <= 2) {
        var totalHours = (daypart * 24) + hours;
        var paddedHours = totalHours.toString().padStart(2, '0');
        var newDuration = paddedHours + ':' + minutes + ':' + seconds;
        g_form.setValue('duration', newDuration);
    }
}

 but in the list view it's still going to show up the day part

 

update the duration field name with your field name and adjust the script if needed

 

ChaitanyaILCR_0-1747745074512.png

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya