Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Script trait - use function logic to return boolean

Avatar

Level 4

Hi,

The OOTB script trait allows us to write script while creating segmentation rules. This has to be boolean expression. When we add a Javascript function to script block like below.

(function (){

  var myFirstVar = "Test";

  var mySecondVar = "Test1"

  if (orderType == "Test" && deviceSKU == "Test1"){

       return true;

  }

})();

The segmentation editor shows the green highlighted background that segment is resolved. But when we access the main page in which teaser component is referring to a campaign linked to above segment with Javascript function, the segment is not getting resolved. If we add just boolean expression, the segment resolves fine in main page.

Is it possible to write Javascript function inside Script trait (so that we can perform more logic)? If so is there a correct way to do this so that main page resolves the segment.

Regards,
Sandeep

1 Accepted Solution

Avatar

Correct answer by
Level 4

Removing colon (;) at the end of function works. Following works

(function (){ 

  var myFirstVar = "Test"; 

  var mySecondVar = "Test1" 

  if (orderType == "Test" && deviceSKU == "Test1"){ 

       return true; 

  } 

})()

Thanks,

Sandeep

View solution in original post

3 Replies

Avatar

Administrator

Which product are your talking here? Adobe Target or Target engine in AEM?



Kautuk Sahni

Avatar

Correct answer by
Level 4

Removing colon (;) at the end of function works. Following works

(function (){ 

  var myFirstVar = "Test"; 

  var mySecondVar = "Test1" 

  if (orderType == "Test" && deviceSKU == "Test1"){ 

       return true; 

  } 

})()

Thanks,

Sandeep