Jelly script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2025 05:39 AM
Hi,
Im using this jelly script but its not evaluating the test condition present bellow is the 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="null">
<g2:evaluate var="mi_sys_id">
var sys_id = RP.getParameterValue("sys_id");
sys_id;
</g2:evaluate>
<g2:evaluate var="jvar_location_supportedby" object="true" jelly="true">
var interaction_location_supportedBy;
var interaction_location_supportedBy2;
var gr = new GlideRecord('interaction');
gr.addQuery('sys_id', jelly.mi_sys_id);
gr.query();
if (gr.next()) {
interaction_location_supportedBy = gr.location.toString();
}
interaction_location_supportedBy.toString() ;
var gr2= new GlideRecord('cmn_location');
gr2.addQuery('sys_id',interaction_location_supportedBy);
gr2.query();
while(gr2.next()){
if(gr2.u_supported_by=='FTS'||gr2.u_supported_by=='Compucom'){
interaction_location_supportedBy2="true";
}
}
interaction_location_supportedBy2;
</g2:evaluate>
$[jvar_location_supportedby]
<j:if test="${jvar_location_supportedby==true}">
<div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;"> $[jvar_location_supportedby] This is a COMPUCOM or OtherServiceName serviced location.
</div>
</j:if>
<!-- $[jvar_location_supportedby] -->
<!-- <j2:if test="$[jvar_location_supportedby == 'FTS']"><div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">
</div></j2:if>
-->
<!-- <j2:if test="$[jvar_location_supportedby=='FTS']">
<div style="color:white;background-color:red;">Major$[SP]Incident</div>
<div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">This is a COMPUCOM or OtherServiceName serviced location.</div>
</j2:if>
<j2:else test=" =$[jvar_location_supportedby=='']">
<div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">hi</div>
</j2:else> -->
<!-- <j2:else >
<div style="color:white;background-color:red;padding-top: .5;padding-top: 0px;border-top-width: 5px;margin-top: 5px;padding-left: 1px;padding-right: 1px;">This is a COMPUCOM or OtherServiceName serviced location.</div>
</j2:else> -->
</j:jelly>
Thankyou in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2025 06:48 AM
Hi @krpandeyadi
You can try this
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="jelly:core" xmlns:g2="null">
<!-- Retrieving sys_id via RP.getParameterValue -->
<g2:evaluate var="mi_sys_id">
var sys_id = RP.getParameterValue("sys_id");
sys_id;
</g2:evaluate>
<!-- Script to check if the location (cmn_location) has u_supported_by set to 'FTS' or 'Compucom' -->
<g2:evaluate var="jvar_location_supportedby" object="true" jelly="true">
var interaction_location_supportedBy; // holds the location sys_id
var interaction_location_supportedBy2; // will store 'true' or empty
// Query the 'interaction' record
var gr = new GlideRecord('interaction');
gr.addQuery('sys_id', jelly.mi_sys_id);
gr.query();
if (gr.next()) {
interaction_location_supportedBy = gr.location.toString();
}
// If the location was found, query cmn_location
var gr2 = new GlideRecord('cmn_location');
gr2.addQuery('sys_id', interaction_location_supportedBy);
gr2.query();
// Iterate results and check the 'u_supported_by' field
while (gr2.next()) {
if (gr2.u_supported_by == 'FTS' || gr2.u_supported_by == 'Compucom') {
interaction_location_supportedBy2 = "true";
break; // exit the loop if found
}
}
// Return the string 'true' or undefined
interaction_location_supportedBy2;
</g2:evaluate>
<!-- 3) (Optional) Display the value for debugging -->
<!-- $[jvar_location_supportedby] -->
<!-- Check if the variable is 'true' (note the quotes in the comparison) -->
<j:if test="${jvar_location_supportedby == 'true'}">
<div style="color:white;background-color:red;padding-top:0.5rem;border-top-width:5px;margin-top:5px;padding-left:1px;padding-right:1px;">
<!-- Display the value and a message -->
$[jvar_location_supportedby] - This is a COMPUCOM or OtherServiceName serviced location.
</div>
</j:if>
</j:jelly>
What changed
String vs. boolean comparison:
Originally, the <j:if> test was:
<j:if test="${jvar_location_supportedby==true}">
But in the internal script, we have:
interaction_location_supportedBy2 = "true";
So interaction_location_supportedBy2 becomes a string "true", not a boolean true.
In Jelly, comparing jvar_location_supportedby == true will not match, because true (boolean) is different from "true" (string).
Solution: Change to:
<j:if test="${jvar_location_supportedby == 'true'}">
Now it correctly compares two matching strings.
Use of break inside the while loop:
As soon as we find a record with u_supported_by set to "FTS" or "Compucom", we do not need to continue iterating. We can set "true" and use break to exit the loop. This is not mandatory, but it saves unnecessary processing.
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Tks
Natan Felipe