Script trait - use function logic to return boolean | Community
Skip to main content
Level 4
June 2, 2017
Solved

Script trait - use function logic to return boolean

  • June 2, 2017
  • 3 replies
  • 1477 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by sandeepk7656774

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

3 replies

kautuk_sahni
Community Manager
Community Manager
June 8, 2017

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

Kautuk Sahni
Level 4
June 9, 2017

This is for Target engine in AEM

sandeepk7656774AuthorAccepted solution
Level 4
June 16, 2017

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