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

suha2
Tera Contributor

@Unique45 

  I have add the value in the correct format but the alert msg will be displayed .

 

suha2_0-1705655092927.png

 

Unique45
Mega Sage

@suha2 

I have created same client script in my PDI , it is working properly:

Please check did you miss anything. Please refer below screenshot:

Unique45_0-1705657738462.png

 

code: 

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;
  }

}

 

Please mark correct/helpful if this helps you!

suha2
Tera Contributor

 Now it's working .Thank you !! 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @suha2 

 

Currency type is not OOTB available. You can use single line text.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************