error field message is getting hidden within 1 sec in record producer onchange script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
I made the below code to show error field message in record producer, when the user add duplicate name then we have to show them the error field message, but sometimes the error message is getting hidden with in 1 sec,
code-
how to fix this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday - last edited Monday
Hi @Amit Dey1
This usually happens because the onChange script runs more than once. When you clear the field value inside the script, it triggers onChange again and the message gets hidden by hideFieldMsg, so it disappears after a second.
Try not to clear the field value in onChange. Instead just show the error when a duplicate is found and hide it only when the value is valid. Once you do that, the message should stay visible and behave consistently.
once try this script and let me know if you face any issues:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.hideFieldMsg('RP_application_name');
return;
}
if (newValue.length > 50) {
g_form.showFieldMsg('RP_application_name', 'Field should not exceed more than 50 characters', 'error');
return;
}
var ga = new GlideAjax('utils');
ga.addParam('sysparm_name', 'checkIfApplicationNameExists');
ga.addParam('sysparm_appName', newValue);
ga.addParam('sysparm_appId', g_form.getValue('RP_app_id'));
ga.getXMLAnswer(function(answer) {
if (answer === 'true') {
g_form.showFieldMsg('RP_application_name', 'Application name already in use.', 'error');
} else {
g_form.hideFieldMsg('RP_application_name');
}
});
}
Thanks
Dimple
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday - last edited Tuesday
actually we have same code in one catalog form also -
