- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 03:16 AM
Hi Team,
I need to know how can i pass multiple values in jelly variables and then add them in query using glide record.
Currently it is overriding the values and i am getting only one value.
Here is my 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:evaluate object="true" var="jvar_statements" jelly="true">
var stmt = new GlideRecord('sn_compliance_policy_statement');
var qr = stmt.addJoinQuery('sn_compliance_m2m_policy_policy_statement', 'sys_id', 'content');
qr.addCondition('document', current.sys_id + '');
qr.orderBy('order');
stmt.query();
stmt;
</g:evaluate>
<j:while test="${jvar_statements.next()}">
<p style="font-weight: bold;"> ${jvar_statements.getValue('name')}</p>
<j:set var="jvar_statements1" value="${jvar_statements.getValue('sys_id')}"/>
</j:while>
<g:evaluate object="true" var="jvar_childstatements" jelly="true">
var pol = new GlideRecord('sn_compliance_policy_statement');
pol.addQuery('parent','${jvar_statements1}');
pol.orderBy('order');
pol.query();
pol;
</g:evaluate>
<j:while test="${jvar_childstatements.next()}">
<a href="sn_compliance_policy_statement.do?sys_id=${jvar_statements.getValue('sys_id')}">${pol.getValue('name')}</a>
</j:while>
</j:jelly>
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 04:22 AM
Hi,
I don't think you can pass value/object from g:evaluate to another g:evaluate
why not query for this table 'sn_compliance_policy_statement' based on the previous query and push the sys_id and name in json object and then iterate over this object using forEach loop;
can you try to update code as below and check whether it works
<?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:evaluate object="true" var="jvar_statements" jelly="true">
var arr = [];
var stmt = new GlideRecord('sn_compliance_policy_statement');
var qr = stmt.addJoinQuery('sn_compliance_m2m_policy_policy_statement', 'sys_id', 'content');
qr.addCondition('document', current.sys_id + '');
qr.orderBy('order');
stmt.query();
while(stmt.next()){
var pol = new GlideRecord('sn_compliance_policy_statement');
pol.addQuery('parent',stmt.sys_id);
pol.orderBy('order');
pol.query();
while(pol.next()){
var jsonObj = {};
jsonObj.sys_id = stmt.sys_id.toString();
jsonObj.name = stmt.name.toString();
arr.push(jsonObj);
}
}
arr;
</g:evaluate>
<j:forEach items="${jvar_statements}" var="jvar_json">
<a href="sn_compliance_policy_statement.do?sys_id=${jvar_json.sys_id}">${jvar_json.name}</a>
</j:forEach>
</j:jelly>
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 04:22 AM
Hi,
I don't think you can pass value/object from g:evaluate to another g:evaluate
why not query for this table 'sn_compliance_policy_statement' based on the previous query and push the sys_id and name in json object and then iterate over this object using forEach loop;
can you try to update code as below and check whether it works
<?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:evaluate object="true" var="jvar_statements" jelly="true">
var arr = [];
var stmt = new GlideRecord('sn_compliance_policy_statement');
var qr = stmt.addJoinQuery('sn_compliance_m2m_policy_policy_statement', 'sys_id', 'content');
qr.addCondition('document', current.sys_id + '');
qr.orderBy('order');
stmt.query();
while(stmt.next()){
var pol = new GlideRecord('sn_compliance_policy_statement');
pol.addQuery('parent',stmt.sys_id);
pol.orderBy('order');
pol.query();
while(pol.next()){
var jsonObj = {};
jsonObj.sys_id = stmt.sys_id.toString();
jsonObj.name = stmt.name.toString();
arr.push(jsonObj);
}
}
arr;
</g:evaluate>
<j:forEach items="${jvar_statements}" var="jvar_json">
<a href="sn_compliance_policy_statement.do?sys_id=${jvar_json.sys_id}">${jvar_json.name}</a>
</j:forEach>
</j:jelly>
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 05:41 AM
Thanks Ankur. But what it is doing with this code is it is displaying the link to parent policy statement.
However i got it working by querying inside the <j:while test="${jvar_statements.next()}"> and running another while.
Based every parent, it displays the child statement link.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2020 06:19 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2021 05:20 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader