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

raj99918
Tera Contributor

@Ankur Bawiskar  Any idea on this one?

Ankur Bawiskar
Tera Patron
Tera Patron

@raj99918 

hide it and then show based on your condition

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

g_form.hideErrorBox('Ticket_id');

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

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar  Still the same no luck.

 

My requirement is like - is mandatory in that variable example format 1234-200 if similar format is given then no need to show any error.

Vishal Birajdar
Giga Sage

Hello @raj99918 

 

Can you try regular expression for catalog variable :

^[a-zA-z0-9]{4}+-[a-zA-z0-9]{4}$

/*This takes 4 character before '-' & 4 char after*/

VishalBirajdar_0-1706529876453.png

 

& use this regular expression on variable

 

VishalBirajdar_1-1706529916872.png

 

 

 

 

Vishal Birajdar
ServiceNow Developer

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