- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2015 01:41 PM
Hi ServiceNow Community Developers,
I have a requirement to define a field called 'Cost' on the Service Catalog form. However when I looked at the list of available variable types on the Service catalog I don't see type Price which is the type that I think this field should be defined as. The default value for this field should be $0.00. Would you please advise as to what I need to do in order to get the desired functionality in this case.
Thanks,
Johannes
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2015 01:59 PM
Hi ServiceNow Community Developers,
I managed to figure this out using a script, here is a script that I wrote which works well for everything i wanted to validate for in the variable:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var cost = g_form.getValue('cost');
cost = cost.trim();
// first character should be dollar sign
var firstChar = cost.substring(0,1);
if (firstChar != '$') {
alert ("Please enter cost in $0.00 format");
g_form.setValue("cost", oldValue);
return;
}
// characters after the $ sign should be numerics
var costType = isNaN(cost.substring(1));
if (costType == true) {
alert ("Please enter cost in $0.00 format");
g_form.setValue("cost", oldValue);
return;
}
// entered value should have a decimal point
var num = cost.substring(1);
if (num.indexOf('.') == -1) {
alert ("Please enter cost in $0.00 format");
g_form.setValue("cost", oldValue);
return;
}
// there must be 2 digits only after the decimal
var decNum = num.substring(num.indexOf('.')+1, num.length);
if (decNum.length != 2) {
alert ("Please enter cost in $0.00 format");
g_form.setValue("cost", oldValue);
return;
}
}
If there is a better to write this I will greatly appreciate it but the above script worked for me.
Thanks,
Johannes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2015 01:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2015 01:53 PM
Hi Edwin,
When you are defining a new variable for a catalog item neither currency type nor price type appears in the list of available types in my instance. The question I have then is how do I see this field type so I can select it as the type for my field.
Thanks for your response.
Johannes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2015 02:15 PM
Sorry Johannes, you are right,
I think there is not an option to use currency fields on service catalog item. Maybe someone will come up with a solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2015 01:59 PM
Hi ServiceNow Community Developers,
I managed to figure this out using a script, here is a script that I wrote which works well for everything i wanted to validate for in the variable:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var cost = g_form.getValue('cost');
cost = cost.trim();
// first character should be dollar sign
var firstChar = cost.substring(0,1);
if (firstChar != '$') {
alert ("Please enter cost in $0.00 format");
g_form.setValue("cost", oldValue);
return;
}
// characters after the $ sign should be numerics
var costType = isNaN(cost.substring(1));
if (costType == true) {
alert ("Please enter cost in $0.00 format");
g_form.setValue("cost", oldValue);
return;
}
// entered value should have a decimal point
var num = cost.substring(1);
if (num.indexOf('.') == -1) {
alert ("Please enter cost in $0.00 format");
g_form.setValue("cost", oldValue);
return;
}
// there must be 2 digits only after the decimal
var decNum = num.substring(num.indexOf('.')+1, num.length);
if (decNum.length != 2) {
alert ("Please enter cost in $0.00 format");
g_form.setValue("cost", oldValue);
return;
}
}
If there is a better to write this I will greatly appreciate it but the above script worked for me.
Thanks,
Johannes