- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2019 11:31 AM
I'm working on one of catalog development , one variable restricted for only numbers ( we need to update only numbers ...if we give letters it should give error). and the number limit to 10 digits only.
Please help me on code needed for onchange client script.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2019 11:34 AM
Hi there,
Something like this?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('your_variable', true);
var val = newValue;
var msg = getMessage('some message');
if((isNaN(val) == true) || (val.length > 10)) {
g_form.showFieldMsg('your_variable', msg, 'error');
}
}
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2019 11:34 AM
Hi there,
Something like this?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('your_variable', true);
var val = newValue;
var msg = getMessage('some message');
if((isNaN(val) == true) || (val.length > 10)) {
g_form.showFieldMsg('your_variable', msg, 'error');
}
}
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2019 11:38 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return; }
//Type appropriate comment here, and begin script below
var age=g_form.getValue('variable name');
if (isNaN(age) )
{
alert("value should be in number");
g_form.setValue('Variable name','');
return false;
}
if(age.length!== 10){
alert("number should be 10 digits");
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2019 04:02 AM
Hi there,
If my answer helped you in any way, please then mark it as helpful.
Please mark this answer as correct if it solves your problem. This will help others who are looking for a similar solution.
Thanks.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field