Validation on catalog variable

raj99918
Tera Contributor

Hi team,

 

I have requirement like '-' is mandatory in one of my variable called "Ticket id' similar to the format like 0000-000 written onchange script but its working for false condition when am giving the favorable condition its still showing as error below is my script.

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   
    var re = /^[a-zA-Z]+-[a-zA-Z0-9]+$/;
    var ID= g_form.getValue('Ticket_id');

    if (!re.test(ID)) {
        g_form.showErrorBox('Ticket_id', ID+ " is not a Ticket ID. Valid Ticket ID should follow 1234-100 format", 'error');

    }

}
6 REPLIES 6

Hi @Vishal Birajdar  Thanks for it but how can we throw an error if it is not a valid one here.

 

Could you please help me with the script here

Hi @raj99918 

 

You can put message in regex itself see below highlighted

 

VishalBirajdar_0-1706531849043.png

 

 

 

Vishal Birajdar
ServiceNow Developer

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