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

Hi Vimal,



The problem lies in the fact that param field is giving you a string value which looks like an array.


If I am retrieving the below from the param field, it has a type of string and not array.



and I am finding it hard to convert back to the array.



[{"fname" :"gaurav","lname" :"bajaj"},


{"fname" : "vimal","lname" : "mishra"}]




Sorry but for now, that's all I can about this issue.



Thanks


Gaurav


Hi Gaurav,



Thank you so much for your reply and time.I will try something and post the answer as well if possible.




Thanks,


Vimal


Hi Gaurav,



Please see the following thread for the solution




How to convert string into JSON object in jelly script?




Thanks,


Vimal


Hi Vimal,



I tried with JSON earlier but somehow it din work for me.
Thanks anyways for sharing the solution.
Happy learning 🙂