setting maximum number on integer field?

Hafila Hatta
Tera Guru

i'm creating a new single line field to be set as integer in a catalog item. how do i set limit to this field so that user can only fill in only up to '9'?

 

thanks

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Hafila Hatta Try the following configuration on your catalog item variable.

 

Screenshot 2024-08-12 at 9.12.35 AM.png

View solution in original post

5 REPLIES 5

Bhavya11
Kilo Patron

Hi @Hafila Hatta ,

 

Please try on-change catalog client script on the single variable with below script

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
     var regexp =/^\d{0,9}$/;
  if(!regexp.test(newValue)){
  alert('Please enter numeric value below 9');
  g_form.setValue('total','');

}

}

 

 to make exactly 9 digits: then replace the regex with

/^\d{4}$/

 

If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

 

 

Thanks,

BK

 

Sandeep Rajput
Tera Patron
Tera Patron

@Hafila Hatta Try the following configuration on your catalog item variable.

 

Screenshot 2024-08-12 at 9.12.35 AM.png

thanks! this is helpful and save me from creating scripts!

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Consider using Regex Variable Validation for this.

- 2019-04-22 - Article - Service Portal Catalog Items: Regex Field Validation

- 2019-08-14 - Article - Regexes for Catalog Items Variable Validation, part 2

 

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn