- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2024 08:13 AM
The catalog client script should retrieve the regex pattern from the country's table and compare it to the input in the 'account_format' variable.
However, the script below is not working. I confirmed that the regex pattern is correct, however it does not display a warning message when the input value is incorrectly formatted.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ctry = g_form.getValue('bank_country');
var rec = new GlideRecord('core_country');
rec.addQuery('sys_id', ctry);
rec.query(function() {
if (rec.next()) {
var pattern = rec.u_pattern; //pattern = regex format stored as string
if (!pattern.test(newValue)) {
alert('Invalid input');
g_form.clearValue('account_format');
}
}
});
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2024 10:19 AM
Did you check your browser console, the below will let you know whether a pattern is found
console.log("Found pattern of " + pattern);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2024 09:00 AM
It's strongly advised to not use GlideRecord client side and instead use GlideAJAX. However to resolve your query:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ctry = g_form.getValue('bank_country');
var countryGR = new GlideRecord('core_country');
countryGR.setLimit(1);
countryGR.query('sys_id', ctry, function(responseGR) {
if (!responseGR.next())
return alert("No Record Found");
var pattern = responseGR.u_pattern;
console.log("Found pattern of " + pattern);
if(!pattern.test(g_form.getValue('field_name_here'))){
alert("Invalid input");
}
})
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2024 10:11 AM
Thanks but this is not returning any alert on wrong input

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2024 10:19 AM
Did you check your browser console, the below will let you know whether a pattern is found
console.log("Found pattern of " + pattern);