Catalog variable to accept decimal values up to 2 digits?

sonali bhagat
Tera Contributor

Catalog variable to accept decimal values up to 2 digits?

it should take whole number but only 2 decimal place should be allowed for decimal value. 

3 REPLIES 3

Robbie
Kilo Patron
Kilo Patron

Hi @sonali bhagat,

 

A common question that has been solved numerous times in the community. 

Let me help recycle someone else's hard work and point you to the following link for solving a $ (Dollar) currency value: 

https://www.servicenow.com/community/developer-articles/service-portal-catalog-items-regex-field-val...

 

Please note, if you just want 2 decimal places and not a specific currency for example, you can use:

Regex: var reg = /^[0-9]*\.[0-9]{2}$/;

Or regular javascript class: var roundValue = parseFloat(newValue).toFixed(2);

 

To help others in the community (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

swapnali ombale
Kilo Sage

for catalog variable validation follow the below process

1. open that particular catalog item

2. open a variable  that you want to validate

3. under variable, there is a "Type Specification" related list section

there is a field "validation Rejex" Select the Number option and open records in a different tab and add regular exprestion 

^\d+\.\d\d$

and save and select a number from the dropdown of validation rejex field.

Robbie
Kilo Patron
Kilo Patron

Hi @sonali bhagat,

 

Did you see my earlier response? Please let me know if I can help close this out for you?

This is a common question that has been solved numerous times in the community. 

Let me help recycle someone else's hard work and point you to the following link for solving a $ (Dollar) currency value: 

https://www.servicenow.com/community/developer-articles/service-portal-catalog-items-regex-field-val...

 

Please note, if you just want 2 decimal places and not a specific currency for example, you can use:

Regex: var reg = /^[0-9]*\.[0-9]{2}$/;

Or regular javascript class: var roundValue = parseFloat(newValue).toFixed(2);

 

@sonali bhagat To help others in the community (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie