- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 02:30 AM
Hello,
I am developing an UI page using Jelly. I am struggling with this because I am not being able to understand how the conditions work.
In summary, I need to show a message depending on a condition (I need a function to retrieve an array and if this array is empty or not, I will show one message or another). I have been testing and I have not been able to do it.
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null" trim="false">
<g2:evaluate var="jvar_reasons" object="true">
var reasons = new ReasonManager().retrieveReasons();
reasons;
</g2:evaluate>
<g2:evaluate var="jvar_no_error" object="true" jelly ="true">
var reasons = jelly.jvar_reasons;
var length = reasons.length;
var result = length > 0;
result;
</g2:evaluate>
<j:set var="jvar_test" value="$[result]"/>
<j:if test="true">
1
</j:if>
<j:if test="$[result]">
2
</j:if>
<j:if test="${jvar_test}">
3
</j:if>
${jvar_test}
$[jvar_no_error]
</j:jelly>
The only number that is being showed is the "1". But, it's very strange because when I show the variables "jvar_test" and "jvar_no_error", both are true. I would really appreciate any help with this issue.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 04:38 AM
I didn't need to use the "toString()", only with j2 I have achieved to show the numbers.
The code :
<?xml version="1.0" encoding="utf-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null" trim="false">
<g2:evaluate var="jvar_reasons" object="true">
var reasons = new ReasonManager().retrieveReasons();
reasons;
</g2:evaluate>
<g2:evaluate var="jvar_no_error" object="true" jelly ="true">
var reasons = jelly.jvar_reasons;
var length = reasons.length;
var result = length > 0;
result;
</g2:evaluate>
<j2:if test="$[jvar_no_error]">
2
</j2:if>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 02:50 AM
Hi,
try to use toString() to compare
Also use j2 since you are using phase 2
<?xml version="1.0" encoding="utf-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null" trim="false">
<g2:evaluate var="jvar_reasons" object="true">
var reasons = new ReasonManager().retrieveReasons();
reasons;
</g2:evaluate>
<g2:evaluate var="jvar_no_error" object="true" jelly ="true">
var reasons = jelly.jvar_reasons;
var length = reasons.length;
var result = length > 0;
result;
</g2:evaluate>
<j2:if test="$[jvar_no_error.toString() == 'true]">
2
</j2:if>
</j:jelly>
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
05-13-2022 04:38 AM
I didn't need to use the "toString()", only with j2 I have achieved to show the numbers.
The code :
<?xml version="1.0" encoding="utf-8"?>
<j:jelly xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null" trim="false">
<g2:evaluate var="jvar_reasons" object="true">
var reasons = new ReasonManager().retrieveReasons();
reasons;
</g2:evaluate>
<g2:evaluate var="jvar_no_error" object="true" jelly ="true">
var reasons = jelly.jvar_reasons;
var length = reasons.length;
var result = length > 0;
result;
</g2:evaluate>
<j2:if test="$[jvar_no_error]">
2
</j2:if>
</j:jelly>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 05:10 AM
Did you mistakenly marked your own response as correct?
I also mentioned the same to use j2 tag
Please mark appropriate response as correct.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader