UI MACRO, How to iterate array of object from Jelly Variable?????

Anuj13
Kilo Contributor

COde 1:- Below code is using for create an array of object.

<g2:evaluate var='jvar_obj1' jelly="true" object="true">
var sComments = new Array();
var gr2 = new GlideRecord('u_triangular_tasting_score');
gr2.addQuery('u_sample_id',current.getValue('u_tri_session_id'));
gr2.addQuery('u_panelist',gs.getUserID());
gr2.addQuery('u_sample',current.getValue('u_sample_label'));
gr2.query();
if(gr2.next())
{
var ids = gr2.u_sample_a_comments.split(',');
var comments = gr2.u_sample_a_comments.getDisplayValue().split(',');
for(var i=0; i&lt;comments.length; i++)
{
sComments[i] = new Object();
sComments[i] = {sys_id: ids[i], value: comments[i]};
}
}
sComments;
</g2:evaluate>

// comment:- below code is used to invoke a macro and pass array as an input.

<g:macro_invoke macro="ub1_slushbucket" obj1="$[jvar_obj1]" /> 

 

Code 2 :- read input array( $[jvar_obj1] ) and print in slushbucket select option View.

//comment:- Below code works fine and print length of the array( which is 6).

<label for="${jvar_name}_left">$[jvar_obj1.length]  </label>

//commnets:- Below code is used to iterate the array which is not working as expected.

<select id="${jvar_name}_right"
name="${jvar_name}_right" class="slushselect form-control"
multiple="yes" size="5" width="60"
onkeydown="${jvar_name}.onKeyMoveRightToLeft(event);"
ondblclick="${jvar_name}.moveRightToLeft();">
<options><j:forEach var="jvar_status" items="${jvar_obj1}">
<option value="${jvar_status.sys_id}">${jvar_status.value}</option>
</j:forEach>
</options>
</select>

 

 

5 REPLIES 5

Deepak Ingale1
Mega Sage

Hi Deepak,

Thanks for reply, but this is not working as expected.

basically i am using two ui macro, in parent macro i am gliding table and storing a list field value in an array object $[jvar_obj1] and passing it at the time of invoking child ui macro in parent :-  <g:macro_invoke macro="ub1_slushbucket" obj1="$[jvar_obj1]" /> .

In child ui macro i am trying to iterate this value but not working as expected. (child macro code can see above in red colour code need to do some change). 

You need to stringify the object in first UI macro  and then do Parse again in second UI macro, that should give you the results.

 

JSON.stringify() and JSON.parse() are the methods

tried but same .... not resolved.