Scripting Alert, Info, and Error Messages

svizcaino
Kilo Contributor

Hi!

i was wondering if someone can help me to understand better what is the difference between gs.addMessage and gs.alert??

I want to use the gs.addMessage for the users, and the gs.alert for the admins.

Can i get a simply example to better understanding?

Thanks and Regards!

-Sergio V.

8 REPLIES 8

Chuck Tomasi
Tera Patron

Hi Sergio,



I don't see any reference to gs.alert(). I don't believe it is a supported GlideSystem method. Where did you see it used?



As for gs.addInfoMessage(), that's going to display a banner message at the top of the screen when called from a server side script.



https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GS-addInfoMessage_O


Dave Smith1
ServiceNow Employee
ServiceNow Employee

I want to use the gs.addMessage for the users, and the gs.alert for the admins.



Can i get a simply example to better understanding?


You probably want to use gs.addInfoMessage() and gs.addErrorMessage() to display messages to the user (there's also g_form.showFieldMsg() and g_form.showErrBox() methods)



Not sure about "for the admins", but for developers consider gs.info(), gs.warn(), gs.error() and gs.log().


divya mishra
Tera Guru

Hey Sergio,




Here we go:


gs.addInfoMessage - gs is nothing but the GlideSystem. In order to show the server-side messages we generally use gs.addInfoMessage.




e.g.


var gr = new GlideRecord("incident");


gr.addQuery("Active",true);


gr.query();


if(gr.next()){


gs.addInfoMessage("I am used in the server-side");


}




gs.alert- basically doesnot exist where as we simply use alert() which is generally used in the simple javascript blocks in the client/browser end.


                    e.g




if(g_user.hasRole("itil')){


alert("Hey now you know the difference :)");


}




post me your feedback


Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response


Have a lovely day ahead




Regards,


Divya Mishra


Anish Reghu
Kilo Sage
Kilo Sage

Is the message displayed on an alert stored somewhere like a log entry in ServiceNow to later refer to which table and what was the message in the alert?

 

Regards,

Anish