Jexl if statements in location schemes

Hi all just noticed the problem with $rx.cond.choose in another thread:

“The reason the $rx.cond.choose is deprecated is that it always evaluates both the true and false expressions.”

I have $rx.cond.choose in location schemes to check for cross site linking.

$rx.cond.choose($sys.crossSiteLink, $sys.site.url, $sys.variables.rxs_urlroot)

Can this be replaced with an if statement?

if($sys.crossSiteLink){$sys.site.url;} else {$sys.variables.rxs_urlroot;}

I have tried but classic Jexl if statement doesn’t appear to be acceptable in the location scheme?

Daniel,

Yes, JEXL if statements work in Location Schemes. The Location Schemes shipped with FastForward include JEXL if Statements.

Try rewriting your statement using the if statement to set the value of a variable:

if($sys.crossSiteLink){$prefix = $sys.site.url;} else {$prefix = $sys.variables.rxs_urlroot;}

As a historical note, the $rx.cond.choose function was implemented because the original release of JEXL used in Rhythmyx did not include an if. A subsequent release added if, making $rx.cond.choose superfluous. The Percussion function continues to work, but we deprecated it in favor of the native option now available in JEXL.

RLJII

I now face another problem as I don’t want the prfix to output anything if it is not a cross site link but if the variable is set to empty the location scheme is outputting a zero in my folder path???

OK OK so it can’t be empty to allow for a relative URL so I must set the variable.

Right I am going insane now. I need a variable to be able to = ‘’ i.e. be emty and not outpu anything in my location scheme in certain cisunstances and this fails.

Help!!!

Daniel,

In an out-of-the-box 6.5.2 installation, I tried setting the value to null if the condition was false:

if($sys.crossSiteLink){$prefix = $sys.site.url;} else {$prefix = '';}

This worked correctly for me. When there was no cross-site link, the prefix was null:

/InvestmentAdvice/EstatePlanning/item340.html

I also tried manually setting the value to zero ({$prefix = ‘0’;}), and the system returned the path with a 0 prepended.

At this point, the forum may not be the most effective way to troubleshoot your situation. I suggest you contact Tech Support for further assistance.

RLJII

Figured this one out!

For your information it appears that I cannot write two consecutive if statements in a location scheme.

So my JSR-170 query:

if($sys.crossSiteLink){$prefix = $sys.site.url;}else{$prefix='';}

if($sys.variables.rxs_subroot != 'none'){$subprefix = $sys.variables.rxs_subroot;}else{$subprefix="";}$prefix + $subprefix +  $sys.pub_path + $sys.item.getProperty

…is invalid and the second if statement is ignored.

The solution is to rewrite the query as one if statement:

if($sys.crossSiteLink && $sys.variables.rxs_subroot != 'none'){$prefix = $sys.site.url + $sys.variables.rxs_subroot;}else if($sys.crossSiteLink && $sys.variables.rxs_subroot == 'none'){$prefix = $sys.site.url;}else if(!$sys.crossSiteLink && $sys.variables.rxs_subroot != 'none'){$prefix = $sys.variables.rxs_subroot;}else{$prefix='';} $prefix + $sys.pub_path