Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards

Mark Solution

Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.

GELÖST

Data Element in a for loop with if statement

Avatar

Level 1

Hi Community,

I'm currently using some custom code in a Data Element to return a price range of a specific product.

This code is working, I'm already using it on pages with a single product.

var productPrice= window.tc_vars.product_unitprice_ttc;
var tranche;

switch (true) {
  case (0 <= productPrice && productPrice < 299):
    tranche = "/Less than 299€";
    break;
  case (299 <= productPrice && productPrice < 301):
    tranche = "/Between 299 and 300€";
    break;
}

 

I would like to use this data element on my basket page where I have multiple products and stock the returned value in an eVar:

s.products = "";

for (var i = 0; i < window.tc_vars.basket_products.length; i++) {
  s.products +=
    /*window.tc_vars.basket_products[i].product_cat2_name +*/ ";" +
    window.tc_vars.basket_products[i].product_id +
    ";"

  if (
    window.tc_vars.basket_products[i].product_unitprice_ttc &&
    window.tc_vars.basket_products[i].product_unitprice_ttc !== ""
  ) {
    s.products +=
      "|eVar34=" + "HOW CAN I USE MY DATA ELEMENT HERE?";
  }
}

 

My goal is to use the formula stocked in my Data Element for every product in my basket. But I'm not sure how to use my data element here.

I know that this is not working:

s.products += "|eVar34=" + window.tc_vars.basket_products[i]._satellite.getVar('ProductPriceTranche');

I tried the following :

s.products += "|eVar34=" + _satellite.getVar('ProductPriceTranche');

It's returning an empty string.

I can't find how to fill in the product index dinamically in this line of code.

 

Any suggestions here ?

Thanks !

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Level 10

Your last code sample is how a DE should be referenced

 

s.products += "|eVar34=" + _satellite.getVar('ProductPriceTranche');

 

 

The DE code should return a value

 

return 'value'

 

Lösung in ursprünglichem Beitrag anzeigen

3 Antworten

Avatar

Korrekte Antwort von
Level 10

Your last code sample is how a DE should be referenced

 

s.products += "|eVar34=" + _satellite.getVar('ProductPriceTranche');

 

 

The DE code should return a value

 

return 'value'

 

Avatar

Level 4

Hi @Andrey_Osadchuk

 

The DE is actually returning a value we forgot to add the last line. But the DE is actually returning the var tranche

return tranche;

So if I'm understanding well your comment, the DE reference is correct so I just need to do some test with some other products ? 

 

Avatar

Level 10

correct