forEach loop is not working in jelly script

vimal11592
Tera Expert

Hi,

I am trying the following code and trying to loop array of object.But it is printing complete array instead of the object from the array.

Code:

<?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:ui_form>

  <g:evaluate var="jvar_gr" object="true">

var gr = new GlideRecord("x_14768_catalyst_bot_library");

gr.addQuery("bot_id", "test_380ee1a0");

gr.query();

gr;

  </g:evaluate>

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

<p>${jvar_gr.getValue('params')}</p>

<j:forEach var="jvar_param" items="${jvar_gr.getValue('params')}">

<p>${jvar_param}</p>

</j:forEach>

</j:while>

</g:ui_form>

</j:jelly>

In above code both <p> tag prints the same value.

error.png

Can someone please help me to fix the issue.

Thanks,

Vimal

8 REPLIES 8

Gaurav Bajaj
Kilo Sage

HI Vimal,



In for each line, you are passing an object in the "items" and not an array,



You would need an array to iterate over it, then only you will be able to see the result.



Instead of it, you can try it using only j: while and get the elements you want on the page.



  1. <j:while test="${gr.next()}">  
  2.   <li>${gr.name} ${gr.email}</li>  
  3. </j:while>


Please mark correct/helpful based on the impact of the response.




Thanks


Gaurav


Hi Gaurav,



Thanks for the reply.



I have attached the screenshot of data it looks like an array of object.Please suggest.




Do I need to remove object="true" from <g:evaluate var="jvar_gr" object="true"> .



I have tried removing object true as well it does not work.I am trying to fix it from a couple of days could not found a solution to fix it.Please any inputs will be helpful.



Thanks,


Vimal


Hi Vimal,



Can you please show the data you want to display on the page.(from the table)


I am assuming that all of them are columns on the table or there is a param column which is having this value.



Also, if you see, you are only getting default value in your screenshot.




Thanks


Gaurav


Hi Gaurav,



I am trying to create input fields in the page with the label.



I am trying to track the name and label from the data.



Just for the explanation.I have one field in the form that has the data as an array of object.(Attached ScreenShot)




data.png



I am trying to read the Param field and loop the data off it and read the name and, a label from the array object.



So based on array length I am trying to create the form with input fields.


Please let me know if you need more info.



Thanks,


Vimal