- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 08:41 AM
Hi,
I am trying to read the table data using GlideRecord in the jelly script.GlideRecord query gives us data as in string format but I have one field in the form that holds the data as follows:
[{"x":"y"},{"a":"b"}]
<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:while>
jvar_gr.getValue('params') returns data as in string but I want to convert it into JSON and loop the data and read the value of x and a.
Can someone please help me to resolve the issue.
Complete 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')}">
------ READ THE VALUES of A and X----
</j:forEach>
</j:while>
</g:ui_form>
</j:jelly>
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 08:56 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 08:56 AM
Could you use JSON.parse() to convert your string to a JSON object?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 09:01 AM
Hi Justin,
Thanks for the reply.I have tried doing the following :
<j:while test="${jvar_gr.next()}" >
<p>${jvar_gr.getValue('params')}</p>
<g:evaluate>
var data = JSON.parse(${jvar_gr.getValue('params')})
</g:evaluate>
<j:forEach var="jvar_param" items="${data}">
------ READ THE VALUES of A and X----
</j:forEach>
</j:while>
It didn't work.Can you please suggest if there are any changes in this.
Thanks,
Vimal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 10:09 AM
Try something like this, maybe.
<j:while test="${jvar_gr.next()}" >
<p>${jvar_gr.getValue('params')}</p>
<g:evaluate var="jvar_obj" object="true">
var obj = JSON.parse(gr.getValue('params'));
obj;
</g:evaluate>
${jvar_obj.a}
<br />
${jvar_obj.x}
</j:while>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2017 10:50 AM
Hi Justin
Thank you so much.I was struggling from couple of days to fix this.
I have tried the code and it worked.
code:
<j:while test="${jvar_gr.next()}" >
<g:evaluate var="jvar_obj" object="true">
var obj = JSON.parse(gr.getValue('params'));
obj;
</g:evaluate>
<j:forEach var="jvar_param" items="${obj}">
<g:evaluate jelly="true" object="true">
var botparam = jelly.jvar_param.label;
var botName = jelly.jvar_param.name;
</g:evaluate>
${botparam}
</j:forEach>
</j:while>
Thanks,
Vimal