Control where system messages appear on a UI page?

davidmcdonald
Kilo Guru

Hi all,

I'm doing something on a UI page, and I'd like to control where the form / system messages appear. These ones:

gs.addInfoMessage("I am a message");

find_real_file.png

At the moment, ServiceNow automatically places them at the top of the page, but I'd like to control where they appear on the page, within another element.

From what I can see, it automatically adds a div that looks like:

<div class="outputmsg_div">

  <div class="outputmsg_container" style="display:" id="output_messages">

            <button class="btn btn-icon close icon-cross" onclick="GlideUI.get().clearOutputMessages(this); return false;"><span class="sr-only">Close Messages"</span></button>

            <div class="outputmsg_div">

                      <div class="outputmsg outputmsg_info notification notification-info">

                      <img title="" class="outputmsg_image" src="images/outputmsg_info_24.gifx" data-original-title="Informational Message">

                                <div class="outputmsg_text">I am a message</div>

                      </div>

            </div>

  </div>

  <script>addRenderEvent(function() {CustomEvent.fire('glide_optics_inspect_update_watchfield', '');});</script>

</div>

Anyone know how to control where messages appear on a UI page?

1 ACCEPTED SOLUTION

davidmcdonald
Kilo Guru

I found a way to do it.



It involves


  1. grabbing the messages
  2. flushing all messages
  3. displaying them in div's classed the same as notifications usually are.


<g:evaluate var="jvar_msg_info" object="true" expression="gs.getInfoMessages();">


<g:evaluate var="jvar_msg_error" object="true" expression="gs.getErrorMessages();">


<g:evaluate>


  gs.flushMessages();


</g:evaluate>



<div class="outputmsg_div">


  <j:forEach var="jvar_value" indexVar="jvar_key" items="${jvar_msg_info}">


            <div class="outputmsg outputmsg_info notification notification-info">${jvar_value}</div>


  </j:forEach>


  <j:forEach var="jvar_value" indexVar="jvar_key" items="${jvar_msg_error}">


            <div class="outputmsg outputmsg_error notification notification-error">${jvar_value}</div>


  </j:forEach>


</div>


View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi David,



infoMessages are always displayed at the top of the form and it comes from ServiceNow platform. you cannot change that.


What is your exact requirement?


Do you want to show infoMessage at some other place or you are asking some question regarding UI page messages i.e. alert etc



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Looking to control where they appear on the screen.



Like how they appear on the hi.service-now.com login page, near the login fields there, instead of always appearing at the top.



find_real_file.png


davidmcdonald
Kilo Guru

I found a way to do it.



It involves


  1. grabbing the messages
  2. flushing all messages
  3. displaying them in div's classed the same as notifications usually are.


<g:evaluate var="jvar_msg_info" object="true" expression="gs.getInfoMessages();">


<g:evaluate var="jvar_msg_error" object="true" expression="gs.getErrorMessages();">


<g:evaluate>


  gs.flushMessages();


</g:evaluate>



<div class="outputmsg_div">


  <j:forEach var="jvar_value" indexVar="jvar_key" items="${jvar_msg_info}">


            <div class="outputmsg outputmsg_info notification notification-info">${jvar_value}</div>


  </j:forEach>


  <j:forEach var="jvar_value" indexVar="jvar_key" items="${jvar_msg_error}">


            <div class="outputmsg outputmsg_error notification notification-error">${jvar_value}</div>


  </j:forEach>


</div>


Hi. I am facing some issue regarding to message in UI Page.. For one specific user, the message is not   getting displayed. Any idea why is it happening?