Hi Team,
We have a requirement to list all product details in the email body shared in the ctx payload,
the payload is as below
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hello Shine,
On your XML, you can't have tags as <product1>... <product2>. It needs to be always just <product>. The correct XML would be:
<ctx>
<orderDetails>
<firstName>Shine</firstName>
<lastName>vv</lastName>
<ctaLink>https://www.test.com </ctaLink>
<pickUpDate>28 Aug 2023 </pickUpDate>
<pickUpStore>XXYY </pickUpStore>
<orderId>TESTORDERID001 </orderId>
<subTotal>22001.00 </subTotal>
<discount>5000.00 </discount>
<tax>1200.00 </tax>
<total>20000.00 </total>
<advanceId>ADVANCEID001 </advanceId>
<advanceAmountPaid>5000.00 </advanceAmountPaid>
</orderDetails>
<productDetails>
<product>
<productName>product1 </productName>
<productImageUrl>https://product1.jpg</productImageUrl>
<productPrice>18000.00 </productPrice>
</product>
<product>
<productName>product2 </productName>
<productImageUrl>https://product2.jpg</productImageUrl>
<productPrice>18000.00 </productPrice>
</product>
</productDetails>
</ctx>
With that in mind, you just need to do a for each loop in the productDetails vector, like such:
<% var xml = new XML(rtEvent.ctx); %>
</br>
<% for each (var item in xml.productDetails.product) { %>
productName: <%= item.productName.toString() %>
</br>
productImageUrl: <%= item.productImageUrl.toString() %>
</br>
productPrice: <%= item.productPrice.toString() %>
</br>
</br>
<% } %>
If you need a count or prefer a for loop, the syntax would be:
<% for (var i = 0; i < xml.productDetails.product.length; i++) {%>
productName: <%= xml.productDetails.product[i].productName.toString() %>
</br>
productImageUrl: <%= xml.productDetails.product[i].productImageUrl.toString() %>
</br>
productPrice: <%= xml.productDetails.product[i].productPrice.toString() %>
</br>
</br>
<% } %>
Let me know if that works for you.
Jorge
Hello Shine,
On your XML, you can't have tags as <product1>... <product2>. It needs to be always just <product>. The correct XML would be:
<ctx>
<orderDetails>
<firstName>Shine</firstName>
<lastName>vv</lastName>
<ctaLink>https://www.test.com </ctaLink>
<pickUpDate>28 Aug 2023 </pickUpDate>
<pickUpStore>XXYY </pickUpStore>
<orderId>TESTORDERID001 </orderId>
<subTotal>22001.00 </subTotal>
<discount>5000.00 </discount>
<tax>1200.00 </tax>
<total>20000.00 </total>
<advanceId>ADVANCEID001 </advanceId>
<advanceAmountPaid>5000.00 </advanceAmountPaid>
</orderDetails>
<productDetails>
<product>
<productName>product1 </productName>
<productImageUrl>https://product1.jpg</productImageUrl>
<productPrice>18000.00 </productPrice>
</product>
<product>
<productName>product2 </productName>
<productImageUrl>https://product2.jpg</productImageUrl>
<productPrice>18000.00 </productPrice>
</product>
</productDetails>
</ctx>
With that in mind, you just need to do a for each loop in the productDetails vector, like such:
<% var xml = new XML(rtEvent.ctx); %>
</br>
<% for each (var item in xml.productDetails.product) { %>
productName: <%= item.productName.toString() %>
</br>
productImageUrl: <%= item.productImageUrl.toString() %>
</br>
productPrice: <%= item.productPrice.toString() %>
</br>
</br>
<% } %>
If you need a count or prefer a for loop, the syntax would be:
<% for (var i = 0; i < xml.productDetails.product.length; i++) {%>
productName: <%= xml.productDetails.product[i].productName.toString() %>
</br>
productImageUrl: <%= xml.productDetails.product[i].productImageUrl.toString() %>
</br>
productPrice: <%= xml.productDetails.product[i].productPrice.toString() %>
</br>
</br>
<% } %>
Let me know if that works for you.
Jorge
Views
Likes
Replies
Views
Likes
Replies