Checking for display and field error messages on client side
The need for checking for error messages as I wanted to perform an onload function based on whether there is an error message after form submission or not. Checking through the wiki did not give me any handy reference to client side error message. I even checked the g_form.hasFieldMsgs method but it was not picking up though it was a handy reference. Written below is a script you can use on your client side to check for any field message error and info. Feel free to modify as you use it.
function formHasFieldMsgs() {
var formHasFieldMsgs = false;
var msgTRsInfo = $(document.body).select('[class$="info"]')
var msgTRsError = $(document.body).select('[class$="error"]') // class$ checks for any class ending in error
if ( msgTRsInfo.length > 0 || msgTRsError.length > 0)
formHasFieldMsgs = true;
return formHasFieldMsgs;
}
https://www.servicenow.com/community/developer-articles/checking-for-display-and-field-error-messages-on-client-side/ta-p/2322979