- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
04-12-2018 12:15 PM
Hello,
We have a vendor who would like an array of skus and the matching prices constructed in a specific way.
We have the skus and the prices in separate variables. Is it possible to use these arrays to construct another array in TIQ?
Existing variables on the page:
sku: ["925913", "893200", "893201"]
sku_price: ["64.99", "74.99", "89.99"]
New variable to be created for this specific vendor:
new_array: ["925913";"64.99"|"893200";"74.99"|"893201";"89.99"]
Thanks for any help,
Jason
04-12-2018 01:15 PM
The first thing to say is that the target structure isn't an array, at least not a valid JS array, it looks more like a delimited string, so the following is an attempt to arrive at that outcome:
var sku_combined = []; if(b.sku.length == b.sku_price.length){ for(var i = 0; i < b.sku.length; i++){ b.sku_combined.push(JSON.stringify(b.sku[i]) + ";" + JSON.stringify(b.sku_price[i])); } }
b.sku_combined = sku_combined.join("|");
Which will set the "sku_combined" UDO variable to the following string:
"925913";"64.99"|"893200";"74.99"|"893201";"89.99"
If the vendor really needs that wrapped in square brackets, you can do it as part of that last operation, but to me it feels a bit weird to start wrapping it in what looks like a JS structure when it's not valid JS...
04-13-2018 07:52 AM
Copyright All Rights Reserved © 2008-2023