- 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 03:28 AM
Hi,
Run your while loop like
<g:evaluate object="true" var="jvar_statements" jelly="true">
var dataval = [];
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){
dataval.push(stmt.sys_id);
}
</g:evaluate>
And use it in
<j:set var="jvar_statements1" value="${dataval}"/>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 03:46 AM
Thanks Sanjeev. Let me try this.
one question-
how is it going to query this in another <g:evaluate> ?
<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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 04:02 AM
My system is getting stucked due this code. I dont think it is correct.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 04:13 AM
HI,
Pass value from URL To UI Page / Macro / Record Producer
#1: Using: JS
Assume iFrame URL has : &req_type=SOMETHING
UI page can have a script like:
function onLoad() {
var url = window.location.toString();
var parms = url.toQueryParams();
if (parms["req_type"] == "SOMETHING") {
/* do something here */
}
}
OR
#2 Using: Jelly
Assume iFrame URL has : &pointer_name=counter
<j:set var="jvar_pointer" value="${RP.getParameterValue('pointer_name')}" />
<j:if test="${jvar_pointer == 'counter'}">
<p>Hello World! - ${jvar_pointer}</p>
/* do something here */
</j:if>
Hope this helps!