How to read array of object using jelly script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2017 05:43 AM
Hi ,
I am trying to read the values from an array of an object using the jelly script but not able to do so.
Jelly script:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="jelly:core" xmlns:g2="glide">
<style>
tr.buttons{height:10px;}
</style>
<g:ui_form>
<g:evaluate var="jvar_short_text" expression="RP.getWindowProperties().short_text" />
<g:evaluate
var="jvar_bot_param"
object="true"
expression="RP.getWindowProperties().bot_param" />
<table width="100%">
<j:forEach items="${jvar_bot_param}" var="jvar_param" indexVar="i">
<p>${jvar_bot_param}</p>
<g:evaluate jelly="true" object="true">
var botparam = jelly.jvar_param[i].label;
var botName = jelly.jvar_param[i].name;
</g:evaluate>
<p>${botparam}</p>
<p>${botName}</p>
</j:forEach>
<tr id="dialog_buttons" class="buttons">
<td colspan="2" align="right">
<g:dialog_buttons_ok_cancel ok='return validateComments(${jvar_bot_param})' ok_type="button" cancel_type="button" />
</td>
</tr>
</table>
</g:ui_form>
</j:jelly>
Var jvar_bot_param has the following data:
[{
"name": "incident_sysid",
"label": "Incident sysid",
"type": "text",
"default": "859245f94ffe7e80c5a3c3818110c7fc"
}]
Can someone please look into my code and suggest me how to retrieve the data from array.
Thanks,
Vimal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 05:33 AM
You are trying to do your Jelly output inside a g:evaluate block.
Try this instead:
<j:forEach items="${jvar_obj}" var="jvar_param" indexVar="i">
<g:evaluate jelly="true" object="true">
var botparam = jelly.jvar_param.label;
var botName = jelly.jvar_param.name;
</g:evaluate>
<p>"${botparam}"</p>
<p>"${botName}"</p>
</j:forEach>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2017 04:09 AM
Hi Chuck,
Thanks for the reply.
I have tried following code :
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="jelly:core" xmlns:g2="glide">
<style>
tr.buttons{height:10px;}
</style>
<g:ui_form>
<g:evaluate var="jvar_short_text" expression="RP.getWindowProperties().short_text" />
<g:evaluate
var="jvar_bot_param"
object="true"
expression="RP.getWindowProperties().bot_param" />
<g:ui_input_field label="${jvar_bot_param}" name="${jvar_bot_param}" />
<j:forEach items="${jvar_obj}" var="jvar_param" indexVar="i">
<g:evaluate jelly="true" object="true">
var botparam = jelly.jvar_param.label;
var botName = jelly.jvar_param.name;
</g:evaluate>
<p>"${botparam}"</p>
<p>"${botName}"</p>
</j:forEach>
</g:ui_form>
</j:jelly>
Attaching the output as a screen shot :
But I am not able to print the value of "botparam" and "botName".Can you please suggest a way to use JSON.parse and JSON.stringify in this.Maybey be data is in string format not object.
Thanks,
Vimal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2017 04:31 AM
Hi Chuck,
Please ignore any other reply.Sorry I have missed some part of the code in that.
Correct Code:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="jelly:core" xmlns:g2="glide">
<style>
tr.buttons{height:10px;}
</style>
<g:ui_form>
<g:evaluate var="jvar_short_text" expression="RP.getWindowProperties().short_text" />
<g:evaluate
var="jvar_bot_param"
object="true"
expression="RP.getWindowProperties().bot_param" />
<g:ui_input_field label="${jvar_bot_param}" name="${jvar_bot_param}" />
<j:set var="jvar_obj" value="${jvar_bot_param}"/>
<j:forEach items="${jvar_obj}" var="jvar_param" indexVar="i">
<g:evaluate jelly="true" object="true">
var botparam = jelly.jvar_param.label;
var botName = jelly.jvar_param.name;
</g:evaluate>
<p>"${botparam}"</p>
<p>"${botName}"</p>
</j:forEach>
</g:ui_form>
</j:jelly>
Output :
Here It seems (I am not sure ) the data that I am trying to loop is in string format, is there any way to use typeof and JSON.parse and JSON.stringify in Jelly Script.
Thanks,
Vimal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2017 06:18 AM
Hi Vimal,
JSON.parse() will work inside your g:evaluate tags. It's standard Javascript. Unfortunatley, I cannot tell which output values go with botparam and which goes with botName and what your desired output is from within these objects to give you specific usage instructions on where to use it and what parts of the object to access once it's converted from a string to an object. Let me know additional details (examples would help) if you need assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2017 06:21 AM
Thanks, Chuck.I will try that and I am looking some other way to solve it.
Thanks for all the input and help.