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.

access jelly variable inside <script> tag

kjmauriello
Mega Expert

I have a UI Page that retrieves data like this:

<g:evaluate var='jvar_events' object='true'>

  var dt = new Date(2015, 0, 15, 0,0,0,0);

  var gr = new isUtils();

  var events = gr.getArrayOfObjects('74ad1ff3c611227d01d25feac2af603f', dt);

  events;

</g:evaluate>

That executes fine, and jvar_events is an array of objects (I confirmed this with a <j:forEach... loop.

I need to pass jvar_events to a jQuery function inside the <script></script> block.

<script>

      var $j_custom = jQuery.noConflict(true);

      $j_custom(document).ready(function () {

              parm1:test,

              parm2: test,

              parm3: ${jvar_events}

</script>

I've tried ${jvar_events}, '$jvar_events}, neither works.

I've also tried executing this inside the <script> and using events as parm3:

  var dt = new Date(2015, 0, 15, 0,0,0,0);

  var gr = new isUtils();

  var events = gr.getArrayOfObjects('74ad1ff3c611227d01d25feac2af603f', dt);

when I create the same array inside the <script> tags with javascript it works fine, so I must not be accessing the jelly variable properly.

I cannot find any valid Wiki or articles on the subject.

Any assistance would be greatly appreciated.

Kevin

11 REPLIES 11

I will give that a try and let you know how it went.   thanks


kjmauriello
Mega Expert

I got this thing working, this is what I did:


I moved the jQuery code from the HTML to the Client Script.


In the Client Script I called the AJAX Script Include, which now returns a JSON.strignify string.


I executed a JSON.parse on the returned data from the AJAX call, which generated the proper array that I was looking for.


I also decided to take the passed in parms and place them in hidden fields in the HTML, allowing me to retrieve them in the Client Script using getElementById.



Thanks for everyone's assistance and suggestions.