Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Coffee Break: Join us on Wednesday, April 5th at 10am PT to chat with Ben Gaines, Director of Product Management for Adobe Analytics. Ben will be online to answer your Analytics and Adobe Summit questions.
SOLVED

Data Element | Custom Code | Products info

Avatar

Level 3

Hi Community,

I have trouble retrieving information from a data element.

I try to retrieve the value of the "condition" variable of my products in a data element "Adobe Analytics - Product - Condition".

Here are some screenshots to explain what I did:

SS_DataElement1.png

 

 

 

 

 

 

 

 

 

 

 

 

Here is the custom code inside:

Returns 1 if the value is "new", else if it's "used" return 0.

 

 

var productCondition;
switch (true){
  case (digitalData.product[0].attributes.condition === "new"):
    productCondition = 1;
    break;
  case (digitalData.product[0].attributes.condition === "used"):
        productCondition = 0;
        break;
}

return productCondition;

 

 

 

 

 

What I can see from the console is the following: 

Swanan__1-1634652492044.png

First I tested the code itself. Then I just tried to call my Data Element.

I'm getting the expected result with the code, but when I call the Data Element, it says it's likely setup incorrectly.

I don't get why. I pushed my data element in my development environment. I'm doing my tests on my development website but I'm not understanding the error here.

 

Does anyone has any suggestions here please ?

 

Thank you

1 Accepted Solution

Avatar

Correct answer by
Level 3

Hi @yuhuisg & @Charles_Thirupathi,

 

Thanks for the cleaner code shared @yuhuisg, really appreciated!

 

@Charles_Thirupathi Thanks for sharing those tips to check the property AND the environment. It helped me to find the issue.

In fact we have 2 channels on the development environment. And my modifications were published on the channel2. But I was checking the Channel1.

 

In case it can help anyone else, here are the steps I went through :

I used the Adobe Experience Platform Debugger to switch the channel.

SS.png

So I went in the Launch tab on the left, then clicked "Actions" 

SS2.png

Then I just had to select my property (1) and the correct channel (2).

 

 

3 Replies

Avatar

Community Advisor

Firstly, that code looks like an "abuse" of the switch statement. I'd rewrite it like so:

var productCondition;
switch (digitalData.product[0].attributes.condition) {
  case "new":
    productCondition = 1;
    break;
  case "used":
    productCondition = 0;
    break;
}

return productCondition;

Anyway, you can try debugging further by setting the initial value of productCondition to your product's condition attribute, i.e.

var productCondition = digitalData.product[0].attributes.condition;

and see if that condition gets returned, instead of "undefined", when you run _satellite.getVar().

Avatar

Level 4

Hi Swanan,

 

Have you verified property and environment of the Launch Embedded Code present in the page your testing? if not kindly verify using syntax's _satellite.environment.stage & _satellite.property.name. The reason for  undefined may be the Data Element your testing is not deployed in the respective Environment you're testing. Also verify the DataElement Name you've provided in _satellite.getVar() syntax(better copy the name from the dataelement you've created). 

If any of the above doesn't resolve the issue kindly share the URL so that i can check and able to find the issue.

 

Thanks,

Charles

Avatar

Correct answer by
Level 3

Hi @yuhuisg & @Charles_Thirupathi,

 

Thanks for the cleaner code shared @yuhuisg, really appreciated!

 

@Charles_Thirupathi Thanks for sharing those tips to check the property AND the environment. It helped me to find the issue.

In fact we have 2 channels on the development environment. And my modifications were published on the channel2. But I was checking the Channel1.

 

In case it can help anyone else, here are the steps I went through :

I used the Adobe Experience Platform Debugger to switch the channel.

SS.png

So I went in the Launch tab on the left, then clicked "Actions" 

SS2.png

Then I just had to select my property (1) and the correct channel (2).