Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Calling Script Include in UI Macro and display return value

reginabautista
Kilo Sage

Hi guys,

I am doing some integration with PagerDuty and getting the On Call Rota using API. I would like to display the retrieved value on the form via a UI Macro.

Looking at   the logs, I know the script include is being called and value being returned, however I am unable to display it on the form. This is what I have so far. Could you please let me know what am I missing? I haven't done any jelly scripting before so I find it challenging.

<tr>

    <td>On Call Manager</td>

    <g2:evaluate var="jvar_your_var" jelly="true">

  var your_var= BFPagerDuty_RetrieveOnCallRotaMgr.retrieveOnCallRotaMgr();

    <p>$[jvar_your_var]</p>

</g2:evaluate>

  </tr>

1 ACCEPTED SOLUTION

What is the API you are calling? What is the name of the Script Include and method? From your script I don't see where you instantiate an object of the Script Include class. If I knew the API you are talking about I would know exactly what script you need but I would expect something like this should do the trick:



<tr>


    <td>On Call Manager</td>


    <g2:evaluate var="jvar_your_var" jelly="true">


var BFPagerDuty_RetrieveOnCallRotaMgr = new BFPagerDuty();


BFPagerDuty_RetrieveOnCallRotaMgr.retrieveOnCallRotaMgr();


</g2:evaluate>


    <p>$[jvar_your_var]</p>


  </tr>



You might want to review these free trainings about Script Includes and Jelly:


https://developer.servicenow.com/app.do#!/training/article/app_store_learn_coding_helsinki_c_Module6...


https://developer.servicenow.com/app.do#!/training/article/app_store_learn_coding_helsinki_c_Module6...


TechNow Episode 1 | ServiceNow Jelly Scripting Part 1 of 3 - YouTube


View solution in original post

9 REPLIES 9

BALAJI40
Mega Sage

Try this one,



<tr>


    <td>On Call Manager</td>


    <g2:evaluate var="jvar_your_var" jelly="true">


  var your_var= BFPagerDuty_RetrieveOnCallRotaMgr.retrieveOnCallRotaMgr();


    <p>your_var</p>


</g2:evaluate>


  </tr>


Mwatkins
ServiceNow Employee
ServiceNow Employee

Problem is that your <p> tags are inside your <g2> tag.



Do this:


<tr>


    <td>On Call Manager</td>


    <g2:evaluate var="jvar_your_var" jelly="true">


  var your_var= BFPagerDuty_RetrieveOnCallRotaMgr.retrieveOnCallRotaMgr();


</g2:evaluate>


    <p>$[jvar_your_var]</p>


  </tr>


Thanks Matthew and balaji, it's giving me this error using both script:




*Undefined(var your_var= BFPagerDuty_RetrieveOnCallRotaMgr.retrieveOnCallRotaMgr();)


Can you please try this code,



<tr>


    <td>On Call Manager</td>


    <g2:evaluate var="jvar_your_var" jelly="true">


  var your_var= BFPagerDuty_RetrieveOnCallRotaMgr.retrieveOnCallRotaMgr();


                your_var


</g2:evaluate>


  </tr>