- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2015 12:12 AM
Within an email notification script, there is a section for including variables associated to a request, within this section there is a conditional that filters out variables where either the label or the value is blank (or false)...
gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text && gr_sc_item_option_mtom.sc_item_option.value
This works, however when trying to port the equivalent logic in jelly (as a JEXL expression) it always resolves as false unless gr_sc_item_option_mtom.sc_item_option.value is boolean value true this is what I have...
<j2:if test="$[gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text && gr_sc_item_option_mtom.sc_item_option.value]">
This is my first UI so I expect this to be a basic error, have tried the following as well...
<j2:if test="$[gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text && (gr_sc_item_option_mtom.sc_item_option.value||(gr_sc_item_option_mtom.sc_item_option.value.length>0))])">
and
<j2:if test="$[gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text && (gr_sc_item_option_mtom.sc_item_option.value||gr_sc_item_option_mtom.sc_item_option.value.notNil())])">
So basically I need a JEXL expression that evaluates anything not Null, empty or false as true
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2015 08:44 PM
John,
Nope..... I spoke too soon. None of that is true except for the statement that does not have a strike through it.
I did some digging around because I wasn't familiar with using "notNil()". However, I have used "nil()". I may be wrong but it seems that "nil()" can be used both with the JSUtil api or not. But I've never seen notNil() used without the JSUtil api.
So I did some experimenting and these are what worked for me:
<j2:if test="$[ JSUtil.notNil(gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text)&& JSUtil.notNil(gr_sc_item_option_mtom.sc_item_option.value) ]">
or
<j2:if test="$[ !gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text.nil() &&!gr_sc_item_option_mtom.sc_item_option.value.nil() ]">
or
<j2:if test="$[ !JSUtil.nil(gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text) && !JSUtil.nil(gr_sc_item_option_mtom.sc_item_option.value) ]">
In conclusion appending ".notNil()" at the end wasn't spitting out neither true nor false when checking the value of either conditional that had it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2015 08:44 PM
John,
Nope..... I spoke too soon. None of that is true except for the statement that does not have a strike through it.
I did some digging around because I wasn't familiar with using "notNil()". However, I have used "nil()". I may be wrong but it seems that "nil()" can be used both with the JSUtil api or not. But I've never seen notNil() used without the JSUtil api.
So I did some experimenting and these are what worked for me:
<j2:if test="$[ JSUtil.notNil(gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text)&& JSUtil.notNil(gr_sc_item_option_mtom.sc_item_option.value) ]">
or
<j2:if test="$[ !gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text.nil() &&!gr_sc_item_option_mtom.sc_item_option.value.nil() ]">
or
<j2:if test="$[ !JSUtil.nil(gr_sc_item_option_mtom.sc_item_option.item_option_new.question_text) && !JSUtil.nil(gr_sc_item_option_mtom.sc_item_option.value) ]">
In conclusion appending ".notNil()" at the end wasn't spitting out neither true nor false when checking the value of either conditional that had it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2015 01:39 AM
It appears there is no way of covering all the scenarios javascript does in one condition without a statement like !(x==null||x==""||x==undefined||x==false) I'll class that as the answer, thanks for your time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2015 04:26 AM
Thanks John. I appreciate it.
But for what it's worth the statements I crossed out are working now. I did a cache.do and simplified everything and tested again. And it appears to use JSUtil.notNil() and just .nil() correctly.
I recorded it just so that I'm not insane:
http://screencast.com/t/AaRkfENAx2ZF
Or maybe I'm doing something totally different than what you're expecting. But at least you can see what I'm doing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2015 04:45 AM
Thanks Chris, the only difference between this and my orginal Q is that boolean false will resolve to true using a notNil, this may actually be preferable (my colleagues have used the nil and notNil methods while I carried on using the javascript convention of how objects evaluate, these methods seem more appealing now inconsistencies between javascript scripts and jelly scripts have come to light, logic is much easier to port from one to the other if you maintain methodology that behaves consistently)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2015 05:33 AM
I found the issue. I did another test and used the sc_item_option where the listings of the item_options_new is a bit different when they belong to an item sitting in an ordered item or cart item.
The issue is the Question field on the sc_item_option record. In my previous example getting data from the question_text as just the item_option_new that field is just a string field where as in sc_item_option it's a reference field. Just stopping at the reference field won't work because it will just return an empty object which does nothing for jelly.
So to get the .nil() or JSUtil.notNil() to work I had to dot walk out to the question_text field. Now everything works as expected in a conditional in the JEXL expression.
Again a recorded screencast:
http://screencast.com/t/RxkPMW1dXKLk