- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2017 08:09 PM
Hello I need some help in writing the onsubmit client script ,thanks in advance
Requirement is if the user enters greater than 24 in hrs field it should not allow the user to save the value and should throw an error
the on submit script which i tried is
I copied it from other client script
it is stoping me if I use less than 24 hrs too , please correct my script if necessary and the timer field is Out of the box .
function onSubmit() {
var time = g_form.getValue('time_worked');
if( time ) {
var day = parseInt(time.split(' ')[0], 10);
if( day ) {
g_form.showErrorBox('time_worked', 'Time worked for a given day cannot exceed 24 hours! Changes to time worked have not been saved', true);
return false;
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 01:03 PM
Use this.
Modified the if condition
function onSubmit() {
//Type appropriate comment here, and begin script below
var a=g_form.getElement('time_worked').value;
alert(a);
var b=a.split(':');
var c=b[0].split(" ");
if(c[0]!=''&& c.length>1)
{
alert("Please enter value less than 24");
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 12:48 PM
Hello Deepak still no use ,thanks for the reply

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 01:09 PM
Let me know the alert result.
function onSubmit() {
var time = g_form.getValue('time_worked');
if( time ) {
var day = parseInt(time.split(' ')[0], 10);
alert("Time worked =" +time);
alert("Days = "+ day);
if( day >= 1 ) {
g_form.showErrorBox('time_worked', 'Time worked for a given day cannot exceed 24 hours! Changes to time worked have not been saved', true);
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 12:26 PM
Hi Kammila,
The timer fields in service-now are not same as the other OOB fields. It won't give you the value with simple getValue() function.
Its works like, if you give a value more than 24, it would take it as 1 extra day and the hours added.
The below script will check if the value entered is more than 24 and give an error.
function onSubmit() {
//Type appropriate comment here, and begin script below
var a=g_form.getElement('time_worked').value;
alert(a);
var b=a.split(':');
var c=b[0].split(" ");
if(c[0]!='')
{
alert("Please enter value less than 24");
return false;
}
}
Please hit like or mark helpful or correct if this solves your issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 12:49 PM
Hello majumder
I tried this but if i enter less than 24 its showing the alert message and not saving
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 12:52 PM