<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Implementing custom code using Adobe Launch - Part 2 in Adobe Analytics Questions</title>
    <link>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/455311#M37693</link>
    <description>&lt;P&gt;Thanks for the insights and explanation. And, that is super helpful in understanding.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried above but it says " illegal return statement"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, when I use the below code in the console which I have put as a custom code in the "ITEM" data element, I get the values printed in the console. Attached is the screenshot. But, when I call that value using _satellite.getvar("ITEM") . It does not print any value&lt;/P&gt;&lt;PRE&gt;(function(){ 
 var products = "";
i=1;
items = JSON.parse(JSON.stringify(bt.order.items));
items.forEach(function(product) {
    		var param = [];
            param.push("ITEM" + i + "=" + product.valuespecificsku);
    		param.push("AMT" + i + "=" + product.price * 0.965);
    		param.push("QTY" + i + "=" + product.quantity);
    		products += "&amp;amp;" + param.join("&amp;amp;");
    		i += 1;
  }); 
  return products;
  })();&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="4d825f4e-3647-4835-b4b1-6bb68f935967.png" style="width: 999px;"&gt;&lt;img src="https://experienceleaguecommunities.adobe.com/t5/image/serverpage/image-id/41660i0BE05E0802E89E7D/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="4d825f4e-3647-4835-b4b1-6bb68f935967.png" alt="4d825f4e-3647-4835-b4b1-6bb68f935967.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jun 2022 21:49:02 GMT</pubDate>
    <dc:creator>asheth2295</dc:creator>
    <dc:date>2022-06-08T21:49:02Z</dc:date>
    <item>
      <title>Implementing custom code using Adobe Launch - Part 2</title>
      <link>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/453335#M37515</link>
      <description>&lt;LI-CODE lang="markup"&gt;&amp;lt;script type='text/javascript'&amp;gt;
document.addEventListener('DOMContentLoaded', function(event) {
    try {
        var img = document.createElement('img'),
    		cjcid = '855555',
    		cjactionid = (document.location.hostname.indexOf('mobile.') &amp;gt; -1) ? '360841' : '348384',
    		products = "",
    		oid = (typeof digitalData !== 'undefined' &amp;amp;&amp;amp; typeof digitalData.order !== 'undefined') ? digitalData.order.id : 'no order id',
    		i = 1,
    		items = (typeof digitalData !== 'undefined' &amp;amp;&amp;amp; typeof digitalData.order !== 'undefined') ? JSON.parse(JSON.stringify(bt.order.items)) : [],
    		eid = digitalData_cookie('cjevent'),
    		cjevent = (eid) ? "&amp;amp;CJEVENT=" + eid : "",
    		src="https://www.emjcd.com/u?" + 
    		        "TYPE=" + cjactionid + 
    		        "&amp;amp;CID=" + cjcid + 
    		        "&amp;amp;CURRENCY=USD" + 
    		        "&amp;amp;OID=" + oid + 
    		        "&amp;amp;METHOD=IMG" + 
    		        cjevent;
    	items.forEach(function(product) {
    		var param = [];
    		param.push("ITEM" + i + "=" + product.valuespecificsku);
    		param.push("AMT" + i + "=" + product.price*.965);
    		param.push("QTY" + i + "=" + product.quantity);
    		products += "&amp;amp;" + param.join("&amp;amp;");
    		i += 1;
    	});
    	img.width = "20";
    	img.height = "1";
    	img.src=src + products;
    	document.body.appendChild(img);
    } catch (ex) {console.log('error: cj: ' + ex.message);}
});
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;I have implemented below based on this&amp;nbsp;&lt;A href="https://urldefense.com/v3/__https:/experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch/m-p/452157*M37371__;Iw!!HMCOyEk!YVEAYrwpPCcz9EtbWkdnuoWwkKv8D0NKU_MFoRW-O0aDOhshwD1b24_uIANi1E4SiPU6goXpNHJir_fhmWj8fwIQqNw$" target="_blank"&gt;Re: Implementing custom code using Adobe Launch&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, My question is how do I implement a for loop like below&amp;nbsp;"ITEM", "AMT", and&amp;nbsp;"PRODUCT" using the custom code. Will it be something like this?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="4a096c9a-a9f6-407a-9e14-6d117a039d94.png" style="width: 400px;"&gt;&lt;img src="https://experienceleaguecommunities.adobe.com/t5/image/serverpage/image-id/41277i9E1D79FF99F75CBD/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="4a096c9a-a9f6-407a-9e14-6d117a039d94.png" alt="4a096c9a-a9f6-407a-9e14-6d117a039d94.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 15:03:11 GMT</pubDate>
      <guid>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/453335#M37515</guid>
      <dc:creator>asheth2295</dc:creator>
      <dc:date>2022-05-25T15:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing custom code using Adobe Launch - Part 2</title>
      <link>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/453390#M37521</link>
      <description>&lt;P&gt;If I understand your post correctly, then yes, the code in your 2nd screenshot will work.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 02:35:51 GMT</pubDate>
      <guid>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/453390#M37521</guid>
      <dc:creator>yuhuisg</dc:creator>
      <dc:date>2022-05-26T02:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing custom code using Adobe Launch - Part 2</title>
      <link>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/453417#M37526</link>
      <description>&lt;P&gt;if the question is how do I create a data element to take in a parameter of type array and iterating through it then the answer is using the &lt;STRONG&gt;event&amp;nbsp;&lt;/STRONG&gt;option for data elements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is a little known fact but you can pass arguments to data element when using custom code as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;//syntax
_satellite.getVar('dataElementID', data);

//argument as array
_satellite.getVar('dataElementID', [1,2,3]);

//argument as object
_satellite.getVar('dataElementID', {"a":"b"});

//argument as primitive
_satellite.getVar('dataElementID', "test");
_satellite.getVar('dataElementID', 1);
_satellite.getVar('dataElementID', true);

//argument as value of another variable
var x = [1,2,3]
_satellite.getVar('dataElementID', x);

&lt;/PRE&gt;&lt;P&gt;Now in your code you simply need to catch the &lt;STRONG&gt;event&amp;nbsp;&lt;/STRONG&gt;variable and you can use its value. So in your data element custom code add for example:&lt;/P&gt;&lt;PRE&gt;console.log(event)&lt;/PRE&gt;&lt;P&gt;Now call you data element in the developer console with one of the syntax above and you should see the value of the argument being printed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If we come back to your loop, there are many ways to achieve this and &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach" target="_self"&gt;forEach&lt;/A&gt; if one of the option. Notice that Adobe Launch supports ES6 and forEach also can return the index which is what I am going to use in my code.&lt;/P&gt;&lt;P&gt;1. Create data element and select custom code&lt;/P&gt;&lt;P&gt;2. We will consider that we will pass the "items" as an argument&lt;/P&gt;&lt;P&gt;3. Code would be as follow:&lt;/P&gt;&lt;PRE&gt;try {
    var items = event;
    //move params outside as ultimately we will output all to products as a return
    var params = [];
    //index is the array index staring at 0
    items.forEach(function(product, index) {
        var i = index + 1;
        params.push(`ITEM${i}=${product.valuespecificsku}`);
        params.push(`AMT${i}=${product.price * .965}`);
        params.push(`QTY${i}=${product.quantity}`);
    });
    return `&amp;amp;${param.join("&amp;amp;")}`;
} catch (e) {
    _satellite.logger.error('[Data Element] Failed in myDataElementName', e);
}&lt;/PRE&gt;&lt;P&gt;Hope this helps, please notice I used my event argument value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here you have a nice dynamic data element, we could think of it as a function that returns a value based on arguments provided&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 07:50:26 GMT</pubDate>
      <guid>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/453417#M37526</guid>
      <dc:creator>Alexis_Cazes_</dc:creator>
      <dc:date>2022-05-26T07:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing custom code using Adobe Launch - Part 2</title>
      <link>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/455311#M37693</link>
      <description>&lt;P&gt;Thanks for the insights and explanation. And, that is super helpful in understanding.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried above but it says " illegal return statement"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, when I use the below code in the console which I have put as a custom code in the "ITEM" data element, I get the values printed in the console. Attached is the screenshot. But, when I call that value using _satellite.getvar("ITEM") . It does not print any value&lt;/P&gt;&lt;PRE&gt;(function(){ 
 var products = "";
i=1;
items = JSON.parse(JSON.stringify(bt.order.items));
items.forEach(function(product) {
    		var param = [];
            param.push("ITEM" + i + "=" + product.valuespecificsku);
    		param.push("AMT" + i + "=" + product.price * 0.965);
    		param.push("QTY" + i + "=" + product.quantity);
    		products += "&amp;amp;" + param.join("&amp;amp;");
    		i += 1;
  }); 
  return products;
  })();&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="4d825f4e-3647-4835-b4b1-6bb68f935967.png" style="width: 999px;"&gt;&lt;img src="https://experienceleaguecommunities.adobe.com/t5/image/serverpage/image-id/41660i0BE05E0802E89E7D/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="4d825f4e-3647-4835-b4b1-6bb68f935967.png" alt="4d825f4e-3647-4835-b4b1-6bb68f935967.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 21:49:02 GMT</pubDate>
      <guid>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/455311#M37693</guid>
      <dc:creator>asheth2295</dc:creator>
      <dc:date>2022-06-08T21:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing custom code using Adobe Launch - Part 2</title>
      <link>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/455333#M37694</link>
      <description>&lt;P&gt;Double check that you're not using the IIFE method in your data element. It should just be the part between the (function { ... }()), i.e.&lt;/P&gt;&lt;PRE&gt; var products = "";
i=1;
items = JSON.parse(JSON.stringify(bt.order.items));
items.forEach(function(product) {
    		var param = [];
            param.push("ITEM" + i + "=" + product.valuespecificsku);
    		param.push("AMT" + i + "=" + product.price * 0.965);
    		param.push("QTY" + i + "=" + product.quantity);
    		products += "&amp;amp;" + param.join("&amp;amp;");
    		i += 1;
  }); 
  return products;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jun 2022 03:18:23 GMT</pubDate>
      <guid>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/455333#M37694</guid>
      <dc:creator>yuhuisg</dc:creator>
      <dc:date>2022-06-09T03:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing custom code using Adobe Launch - Part 2</title>
      <link>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/455507#M37708</link>
      <description>&lt;P&gt;Thank you.. That was super helpful regarding the IIFE method.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2022 19:57:10 GMT</pubDate>
      <guid>https://experienceleaguecommunities.adobe.com/t5/adobe-analytics-questions/implementing-custom-code-using-adobe-launch-part-2/m-p/455507#M37708</guid>
      <dc:creator>asheth2295</dc:creator>
      <dc:date>2022-06-09T19:57:10Z</dc:date>
    </item>
  </channel>
</rss>

