We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

GlideAjax is not defined in UI macro

rsadhula
Mega Contributor

Hi All,

I'm calling GlideAjax from UI Macro , but I'm facing below error:

org.mozilla.javascript.EcmaError: "GlideAjax" is not defined.

Caused by error in ftp://gsft_database/asp_cms_header_user_welcome.3 at line 2

1:

==> 2: var ga = new GlideAjax('global.GetHostName');

3: ga.getXMLWait();

4: var hostName = ga.getAnswer();

5:

My UI Macro looks like below:

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g:evaluate>

var ga = new GlideAjax('global.GetHostName');

ga.getXMLWait();

var hostName = ga.getAnswer();  

     

</g:evaluate>

<!--<j:set var="jvar_inc" value="${help_sysid}" />-->

    <span id="asp-cms-user-salutation">

          ${gs.getMessage('Welcome')},

          <j:if test="${!gs.getUser().isXML()}">

                <span id="asp-cms-user-name"><a href="profile.do">${gs.getUserDisplayName()}</a></span>

<span id="asp-cms-user-sysname">${hostName}</span>

          </j:if>

         

    </span>

</j:jelly>

What I'm doing wrong here ??

5 REPLIES 5

Kalaiarasan Pus
Giga Sage

evaluate tags are like server side scripting. You can call the scripts directly as below.



var script = new scriptinclude();


script.functionname();


Thanks for the info, I would need to print user's computer name in ess page,


how can I do that, some link or info would be much appreciated,


Hi Rakesh,



When you use <g:evaluate> tag you can use that variable in html section as below:


the variable jvar_computerName has the value



<g:evaluate var="jvar_computerName" jelly="true">



// query whatever table you want and store it in variable and then you can use it in html


var gr = new GlideRecord();


gr.addQuery();


gr.query();


var computerName = gr.computer_name; // have your field here which stores computer name


computerName;


</g:evaluate>



<p>${jvar_computerName}</p>



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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,



We don't save computer name in table, I would like to display computer name dynamically for end user.


Is this possible ?



I tried with HostNameJs but it's not working as expected.