Validation on catalog variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:36 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:37 AM
@Ankur Bawiskar Any idea on this one?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:42 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:46 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 04:06 AM
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*/
& use this regular expression on variable
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates