How to add field message to selectbox

Appu
Tera Guru

Hi All,

i am creating a catalog item in that I have a select box as Impact with choices as Level 1, Level 2, and Level 3

if level 1 is selected i need a text to be displayed similarly for level 2 and level 3 but the texts are different.

how do I do that? kindly help me

1 ACCEPTED SOLUTION

Hi,

you should be using the variable name which is impact and values as L-1 etc

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    
g_form.hideFieldMsg('impact');

if(newValue == 'L-1'){
g_form.showFieldMsg('impact', 'TESTING Message 1' ,'error', true);

if(newValue == 'L-2'){
g_form.showFieldMsg('impact','TESTING Message 2','error', true);
}

if(newValue == 'L-3'){
g_form.showFieldMsg('impact','TESTING Message 3','error', true);
}

}

Regards
Ankur

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

View solution in original post

8 REPLIES 8

Martin Kohler
Tera Guru

Hi appu,

you can create a catalog client script with type onChange for that variable and use g_form.addInfoMessage for each of the choices of the variable.

Hope that helps.

 

Kind regards,

Martin

Ian Mildon
Tera Guru

If you are wanting a message to appear under the field, use something similar to this:

g_form.showFieldMsg('<field name>', '<message text>', '<level>');
 
If you add 'error' for the level, the message will be in red; adding 'info' will give blue text.

Ankur Bawiskar
Tera Patron
Tera Patron

@appu 

sample catalog client script

Ensure you select

UI Type -  ALL

Applies to catalog Item -  True

Use proper variable name

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    
    g_form.hideFieldMsg('your_variable'); // give here your variable name

if(newValue == 'Level 1'){
g_form.showFieldMsg('your_variable', 'Level 1 Message' ,'error', true); // give here your variable name
}

if(newValue == 'Level 2'){
g_form.showFieldMsg('your_variable','Level 2 Message','error', true); // give here your variable name
}

if(newValue == 'Level 3'){
g_form.showFieldMsg('your_variable','Level 3 Message','error', true); // give here your variable name
}

}

Regards
Ankur

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

@appu

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

 

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