Custom code Data Element returning empty value

Kamil84

25-06-2020

Hi, I tried using the below custom code to capture dropdown selection values as data element. It works in console but when i input the code as a data element and check the _satellite.getVar() for this data element, it just returns an empty value "". 

My Javascript is basic and i am fairly new to Adobe Launch so step by step instructions with visuals would be great.

Thank you

 

var selectElm = document.querySelector("#order_retailer_name")
selectElm.addEventListener("click",function(){
var elm = this;
var selectedElm = elm.options[elm.selectedIndex].textContent;
return selectElm;
});

View Entire Topic

Andrey_Osadchuk

MVP

25-06-2020

That code will not work in Data Element custom code as it's asynchronous.

One of the options is as follows:

  1. create a rule with Click event mapped to the CSS selector #order_retailer_name
  2. define a custom variable inside Conditions via a custom code
    var elm = this;
    _satellite.setVar('name', elm.options[elm.selectedIndex].textContent)
  3. Reference the custom variable by name as a data element where necessary