I want to create a "numeric" and "currency" type variable in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 11:08 AM
Hi,
I have a requirement to create two variables which are off Currency and Numeric type variables.
Thanks,
Vaishnavi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 11:26 AM
Hello @Vaishnavi35 As these type of variables are not present in catalog items you might have to find a custom way to do it.
For numeric field you can create a string type variable and write an on change client script on that field like below
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var numVal=g_form.getValue('your_string_field_name');
if (isNaN(numVal))
{
alert("Input should only be in numbers");
g_form.setValue('your_string_field_name','');
return false;
}
}
For currency field you can try this by creating a string field and then validating it like in below solution
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 07:54 AM
Numeric value validation script does not work.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var numVal = g_form.getValue('u_dollar_amount');
if (isNaN(numVal)) {
alert("Input should only be in numbers");
g_form.setValue('u_dollar_amount', '');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 11:43 AM
Hi @Vaishnavi35 ,
Hope you are doing great.
We dont have OOB variable present in servicenow of type currency or Numeric type variable. But you can acheive it by building logic in on change script which will only allow for currency type value for particular field, or other value it can show you alert popup and can clear value out if entered value of other type.
1. Numeric type : PFB reference script for same :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var numVal = g_form.getValue('your_string_field_name');
if (isNaN(numVal)) {
alert("Input should only be in numbers");
g_form.setValue('your_string_field_name', '');
return false;
}
}
Similarly you can put your logic in on chaneg script for currency type variable.
Regards,
Riya Verma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 07:55 AM
Hi Riya,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var numVal = g_form.getValue('u_dollar_amount');
if (isNaN(numVal)) {
alert("Input should only be in numbers");
g_form.setValue('u_dollar_amount', '');
return false;
}
}
Thanks & Regards,
Vaishnavi
The script does not work somehow. If you can please help?