Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

showFieldMsg duplicates in my client script when I use hideFieldMsg and then show it again

abrahams
Kilo Sage

I am tying to use showFieldMsg in my Service Catalog client script. I like the look of the g_form.showFieldMsg('field_name') however if I show it when the user makes an error ... then hide it using g_form.hideFieldMsg('field_name') when they make the correct entry ... then for what ever reason they make another error on that same field (they must be having a bad day) it will now show 2 error messages when I user g_form.showFieldMsg('field_name') to display the error to them again. I would like to use this instead of the javascript alert if I could stop the showFieldMsg messages from multiplying. Does anyone know if this is possible?

7 REPLIES 7

The first thing I notice is that you've got things like 'TypeOfChange' and 'JobTitle' which don't correspond to any fields I'm aware of. I assume these are names of service catalog variables of some kind but it's probably a good idea to double check those just in case. The approach I generally take is to start my onChange script with a line to hide any existing field message to avoid duplicates. Then I do the processing to add the field message. Something like this...



function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading) {
//Hide any existing field message for the 'TypeOfChange' field to avoid duplicates
g_form.hideFieldMsg('TypeOfChange');

//See if we need to add a new field message
var comp = g_form.getValue('CompanyName');
var dep = g_form.getValue('Department');
var jt = g_form.getValue('JobTitle');
var t = g_form.getValue('TypeOfChange');
if (t != '') {
if (comp == '' || dep == '' || jt == '') {
g_form.setValue('TypeOfChange','');
g_form.showFieldMsg('TypeOfChange','Company, Department and Job Title are required prior to selecting response for Type of Change','error',false);
}
}
}


abrahams
Kilo Sage

The 'TypeOfChange' and 'JobTitle' are variables in the Service Catalog Item that I created. Your logic works great. Thank you so very much!!!


Ed_Jones
Kilo Contributor

Awesome.. Thanks