Duration Type field auto conversion

Anubhav24
Mega Sage
Mega Sage

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.

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Anubhav24 

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.

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

@Ankur Bawiskar 

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.

@Anubhav24 

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

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

@Anubhav24 

then it would be difficult to determine.

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