I wanna create variable in record producer. That variable should have values only in between 500 to 5000. by default it should hold 5000.

Sachin Gavhane
Giga Guru

I wanna create variable in record producer. That variable should have values only in between 500 to 5000. by default it should hold 5000.

4 REPLIES 4

Abhijit4
Mega Sage

You can create single line text field and write onchange client script to check if enterd value is between 500 to 5000. if not then show error and clear field.

You can define default value as shown below

find_real_file.png

Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Vishal Birajdar
Giga Sage

Hello Sachin,

You can find solution below

1. Set the regex validation for your variable 

find_real_file.png

 

2. Set default Value to 5000

find_real_file.png

 

3.Write onChange Client script to validate number is in range

find_real_file.png

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Ankur Bawiskar
Tera Patron
Tera Patron

What did you start with and where are you stuck?

Regards
Ankur

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

Muhammad Khan
Mega Sage
Mega Sage

Hi @Sachin Gavhane 

 

Create a regular expression, see the below image for reference.

find_real_file.png

Below is the explanation of the regular expression.

// ^[5-9]+\d{2}|^[1-4]+\d{3}|^[5]+0+0+0+


// Here we are targeting 500-999
// ^[5-9]+ means number starts with at least one (+ indicates at least one) of 5, 6, 7, 8, 9 
// \d{2} means after that it will contain 2-digits, which could be any from 0-9

// | it is like an OR, which means if above not found search for other expression

// Here we are targeting 1000-4999
// ^[1-4]+means number starts with at least one (+ indicates at least one) of 1, 2, 3, 4 
// \d{3} means after that it will contain 3-digits, which could be any from 0-9

// | it is like an OR, which means if above not found search for other expression

// Here we are targeting 5000 only
// ^[5]+means number starts with at least one (+ indicates at least one) 5
// 0+ means contains at least one 0
// 0+ means contains at least one 0
// 0+ means contains at least one 0

 

Then create a variable and select the regex which you created above. See the below image for reference.

find_real_file.png

Portal Output

find_real_file.png

Native UI Output

find_real_file.png

 

To define default value, specify it as 5000 in the default value tab/section of the variable.

 

Hopefully, this will resolve your query.