Add currency variable  for catalog item in service catalog

suha2
Tera Contributor

Hi All, 

How to add currency variable  for catalog item in service catalog ,   do you have any idea how to do that ?

 

field label

type

 

Preferred phone price

Currency Input

Currency input field. Euro/Pound Symbol

1 ACCEPTED SOLUTION

Unique45
Mega Sage

Hello @suha2 ,

As Currency variable type is not present in the catalog item you need to create Single Line text type variable and you need add validations to it by creating onChange Client script.

The below link will help to create onChange client script so, go through below link:

https://www.servicenow.com/community/developer-forum/how-to-define-variables-of-type-price-in-the-se...

 

Please mark correct/helpful if this helps you!

View solution in original post

8 REPLIES 8

Unique45
Mega Sage

Hello @suha2 ,

As Currency variable type is not present in the catalog item you need to create Single Line text type variable and you need add validations to it by creating onChange Client script.

The below link will help to create onChange client script so, go through below link:

https://www.servicenow.com/community/developer-forum/how-to-define-variables-of-type-price-in-the-se...

 

Please mark correct/helpful if this helps you!

suha2
Tera Contributor

Thank you !!

suha2
Tera Contributor

Hi,

I had try this script in catalog client script but it show me the alert after i enter the  currency in the field .do you have any idea how to solve that?

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
 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;
  }

}
suha2_0-1705652969421.png

 

Unique45
Mega Sage

@suha2 ,

If you add a value that is not in the format of '$0.00', then the alert message will be displayed and the value will be cleared.

The alert will not appear if you add the value in the correct format.

 

 

Please mark correct/helpful if this helps you!