Creating an Error Message in Client Script

aubreysallee
Kilo Contributor

I'm a novice in JS so I'm having some difficulty making a client script to make an error message on the Demand form   to tell the user they need to answer a question in a choice field before continuing if the "portfolio" field contains a value of "AIT." Any suggestions would be very appreciated! At this point I have not found a suitable script to tweak for my purpose, but I do know I probably need to use "getErrorMessage." Thanks!

12 REPLIES 12

Hello Aubrey,



If my understanding is correct then the user might either select yes or no as an option. Correct?


If yes then you need to check if there was any modification on field or not. Sample script.



var chk = g_form.getControl('PASS FIELD COLUMN NAME OF CHECKBOX HERE');


if(!chk.changed)


{ //enter the loop if user has not taken any action.


alert('a');


}


arnabbose
Tera Expert

Look at Scripting Alert, Info, and Error Messages - ServiceNow Wiki   , this should help your purpose.


eduardo gushike
Tera Contributor

Hi guys!

 

In my case I used a default GlideModal to display an 'alert message', on the client side, code example:

 

function your_func (whatever_condition) {
    if (!whatever_condition)
        return modalAlert();
}

function modalAlert() {
   var gm = new GlideModal('glide_info', true, 600);
   gm.setTitle('Atention!');
   gm.setPreference("title", 'your message');
   gm.render();
}