Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

how to create variable which displays Price (always US Dollars)

Deepa12
Tera Contributor

Hi,

Please advise to create variable for catalog item which is always show US dollar currency.

This variable value comes from the table software table annual cost (customized field). Thanks.

 

7 REPLIES 7

@Deepa12 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Dinesh Chilaka
Tera Guru

Hi @Deepa12 ,

Create a variable of type Custom and if we create a custom variable there is an ability to add portal widgets .

So OOB there is a currency widget is available and add that widget to this variable.

If my response helped,mark it as helpful and accept the solution.

 

Tejas Adhalrao
Kilo Sage

Hi @Deepa12  ,

 there is not currency type variable , you have to create the single line text and show the field message using on load client script "Please enter cost in $0.00 format".

 

and using the on change client script you can validate the value entered by the users . here is on change client script you can try 

 

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

you can add more validation you want, take help of ai to modify script and logic you have to appilied . thank you 

 

 

If you found my solution helpful, please mark it as Helpful or Accepted Solution...!

thanks,

tejas

Email: adhalraotejas1018@gmail.com

LinkedIn: https://www.linkedin.com/in/tejas1018