- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 12:55 AM
Hi All,
I have a variable which is single line text, this should only accept numeric values. Please let me know how I can achieve this.
Thanks,
Shugufta
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 01:05 AM
Hi,
Write an onChange client script. One sample is below
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var numnericVal=g_form.getValue('your field name');
if (isNaN(numnericVal)) // check if value is not numeric
{
alert("Please enter numeric values");
g_form.setValue('your field name', ''); // Set the field to empty
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 01:45 AM
Can you please place the code here of what you have written.
g_form.addErrorMessage("your message"); is the correct syntex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 02:35 AM
Hi Akash,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//g_form.hideFieldMsg("estimated_size", true);
var numericVal=g_form.getValue("estimated_size");
var strMsg = "Please enter numeric values";
if (isNaN(numericVal)) // check if value is not numeric
{
//alert("Please enter numeric values");
g_form.showErrorBox("estimated_size", strMsg, true);
g_form.setValue("estimated_size", ""); // Set the field to empty
}
else {
g_form.hideFieldMsg("estimated_size", true);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 02:53 AM
Can you try showFieldMessage()
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#showFieldMsg
g_form.showFieldMessage('estimated_size',"Your Message",'error');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 03:02 AM
Hi Akash,
I tried it is not giving me the error message.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 03:02 AM
apologies i typed the wrong function name
g_form.showFieldMsg('estimated_size',"Your Message",'error');