Looping through an array in JellyScript

Alex Ng
Tera Contributor

Hi all,

I have a single dimension array that was populated in the <g2> tag in UI Page. In the same page, I wanted to loop through this array in the jelly tag to populate a table in HTML. Does anyone knows how to do this? The code I had in <g2> tag is as followed and needs to be converted to jellyscript for the looping:

for (var i = 0; i < assignedIdList.length; i++) {

gs.print(assignedIdList[i]);

}

Your help is appreciated.

Thank you.

5 REPLIES 5

manikorada
ServiceNow Employee
ServiceNow Employee

Alex,



You can check this link : Jelly: Over and Over Again...


Also, the code will be something like:


//impArr1 is the Array name


<j:forEach var="jvar_pair" items="$[impArr1]" indexVar="jvar_i">


<g:evaluate var="jvar_cat" expression="var sp = $[jvar_index]; sp;" />


$[javr_cat]


</j:forEach>


Anurag Tripathi
Mega Patron
Mega Patron

Hi Alex



use this


<j2:forEach var="jvar_upd" items="$[jvar_updates]">


  <br/>$[jvar_upd]


  </j2:forEach>




jvar_updates is the array


-Anurag

Anurag Tripathi
Mega Patron
Mega Patron

Hi Alex



use this


<j2:forEach var="jvar_upd" items="$[jvar_updates]">


  <br/>$[jvar_upd]


  </j2:forEach>




jvar_updates is the array


-Anurag

Alex Ng
Tera Contributor

Hi everyone,



Thanks for all the replies. I used something similar of the abov


e but I do not seems to get the value through. Below is the part of my code in UI Page.



<g:evaluate>  


              var colors = [  


                      { name: 'red', value: '#FF0000' },  


                      { name: 'blue', value: '#0000FF' }  


              ];  


</g:evaluate>  



<j:forEach items="${colors}" var="jvar_color">              


      <tr>


          <td>${colors}</td>


          <td>${colors.name}</td>


          <td>${colors.value}</td>


      </tr>


</j:forEach>  



It does manage to loop through 2 rows of records but {colors.name} and ${colors.value} returns me an empty value while ${colors} actually returns me the value of org.mozilla.javascript.NativeArray@8b7f18.



Anyone can shed some light to me of what I am doing wrong?



Thank you.