The CreatorCon Call for Content is officially open! Get started here.

Jelly script populating innerHTML

xiaix
Tera Guru

I'm trying to get the following to work:

<?xml version="1.0" encoding="utf-8" ?>

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

      <g:evaluate jelly="true">

              var gr = new GlideRecord('sys_user_grmember');

              gr.addQuery('group', '8a4cd5b36fd3d1000fd9122cbb3ee48f'); // "Service Desk" group sys_id.

              gr.orderBy('user.name');

              gr.query();        

      </g:evaluate>

             

      <j:while test="${gr.next()}">

              <div id="${gr.user.sys_id}"></div>

      </j:while>

      <g:evaluate jelly="true">    

              var gr2 = new GlideRecord('u_round_robin');

              gr2.query();

             

              while (gr2.next())

              {

                      document.getElementById('gr2.u_user_sys_id').innerHTML = gr2.u_daily_tickets_assigned;

              }

      </g:evaluate>

     

</j:jelly>

This is the part that isn't working:

document.getElementById('gr2.u_user_sys_id').innerHTML = gr2.u_daily_tickets_assigned;

I'm sure that I'm not using jelly correctly.   Can someone please advise?

8 REPLIES 8

Artemis15
Kilo Guru

Hi David,




Try this:




<script>


document.getElementById('"'+gr2.u_user_sys_id+'"').innerHTML = gr2.u_daily_tickets_assigned;


</script>


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi David,



Inside of jelly you can only run server side javascript, not client side. You actually don't need the client side at all as you can just use a j:while to print our the contents. If you need them to be inside of div you can just run the jelly inside of the div tags.



<?xml version="1.0" encoding="utf-8" ?>  


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


 


      <g:evaluate jelly="true">  


              var gr = new GlideRecord('sys_user_grmember');  


              gr.addQuery('group', '8a4cd5b36fd3d1000fd9122cbb3ee48f'); // "Service Desk" group sys_id.  


              gr.orderBy('user.name');  


              gr.query();            


      </g:evaluate>  


                 


      <j:while test="${gr.next()}">  


              <div id="${gr.user.sys_id}">


                      <g:evaluate jelly="true">        


                              var gr2 = new GlideRecord('u_round_robin');  


                              gr2.query();  


                                 


                              while (gr2.next())  


                              {  


                                      document.getElementById('gr2.u_user_sys_id').innerHTML = gr2.u_daily_tickets_assigned;  


                              }  


                      </g:evaluate>


                      <j:while test="${gr2.next()}">


                              gr2.u_daily_tickets_assigned;


                      </j:while>


              </div>  


      </j:while>


     


</j:jelly>



If you really needed to run the client side javascript you'd need to put it inside of script tags.


Yeah, unfortunately that didn't print out anything.



Here's the actual code I'm using (in full).   Please take note of the very end where I use


document.getElementById('${uid}').innerHTML = ${numb};



For some reason, it's only working on 1 user and the rest are blank.



<?xml version="1.0" encoding="utf-8" ?>


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



      <g:evaluate jelly="true">


              var gr = new GlideRecord('sys_user_grmember');


              gr.addQuery('group', '8a4cd5b36fd3d1000fd9122cbb3ee48f'); // "Service Desk" group sys_id.


              gr.orderBy('user.name');


              gr.query();


             


              var gdt = new GlideDateTime();


              var month = gdt.getMonth();


              var year = gdt.getYear();


              var day = gdt.getDayOfMonth();


             


              var gr2 = new GlideRecord('u_round_robin');


              gr2.addQuery('u_year', year);


              gr2.addQuery('u_month', month);


              gr2.addQuery('u_day_of_month', day);


              gr2.query();


             


              var usrAry = [];


             


              while (gr2.next())


              {


                      usrAry.push({ id: gr2.u_user_sys_id, num: gr2.u_daily_tickets_assigned });


              }


      </g:evaluate>


     


      <script>


              var activeCount = 0;


              var inactiveCount = 0;


             


              function add(val)


              {


                      if (val == "a")


                              activeCount++;


                      else if (val == "i")


                              inactiveCount++;


              }


      </script>



      <style>


              .trHover tr:hover td {background:#d7d7d7}


      </style>


              <table class="trHover">


                      <div id="stats">


                      </div>


                      <tr>


                              <td>


                                      <span style="text-decoration: underline;">Technician</span>


                              </td>


                              <td>


                                      <span style="text-decoration: underline;">#</span>


                              </td>


                              <td>


                                      <span style="text-decoration: underline;">Last ticket assigned</span>


                              </td>


                      </tr>


                      <j:while test="${gr.next()}">


                              <tr>


                                      <td>


                                              <a target="_top" href="nav_to.do?uri=sys_user.do?sys_id=${gr.user.sys_id}">


                                                      <j:if test="${gr.user.u_round_robin_active}">


                                                              <span style="background-color: #5CE65C;font-weight: bold;">${gr.user.name}</span>


                                                              <script> add("a"); </script>


                                                      </j:if>


                                                      <j:if test="${!gr.user.u_round_robin_active}">


                                                              <i>${gr.user.name}</i>


                                                              <script> add("i"); </script>


                                                      </j:if>


                                              </a>


                                      </td>


                                      <td width="10">


                                              <span id="${gr.user.sys_id}"></span>


                                      </td>


                                      <td>


                                              <j:if test="${gr.user.u_round_robin_active}">


                                                      (${gr.user.u_last_ticket_assigned.getDisplayValue()})


                                              </j:if>


                                              <j:if test="${!gr.user.u_round_robin_active}">


                                                      &#160;


                                              </j:if>


                                      </td>


                              </tr>


                      </j:while>


      </table>


             


      <script>


              var tot = activeCount + inactiveCount;


              document.getElementById("stats").innerHTML = "On:&#160;" + activeCount + "&#160;&#160;&#160;Off:&#160;" + inactiveCount + "&#160;&#160;&#160;Total:&#160;" + tot + "<br /><i>(color indicates Round Robin is activated)</i><br /><br />";


      </script>


     


      <j:forEach var="jvar_word" items="${usrAry}">


              <g:evaluate var="jvar_numb" jelly="true" expression="var numb = jelly.jvar_word.num; numb;" />


              <g:evaluate var="jvar_uid" jelly="true" expression="var uid = jelly.jvar_word.id; uid;" />


                      <script>


                              document.getElementById('${uid}').innerHTML = ${numb};


                      </script>            


      </j:forEach>


     


     


</j:jelly>






Here's the output:


Screen Shot 07-21-15 at 09.47 AM.JPG



Notice the "6" after Marci.   I have no idea why this is the ONLY one that shows up.


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi David,



I think you should be able to nest your queries rather than setting innerHTML. Could you describe what you're trying to do there?