Avatar

Correct answer by
Level 4

Hi ShivaDT,

First, don't use xtk.session.Write for temporary schemas. Even if you manage it to work, it will be super slow.

If you need to modify flow data, export the file via data export comonent to the server HDD. By default the file will be stored in var/<Instance Name>/export folder. Use Javascript code to open the file, modify its lines and save it into another file. Use data load component to load the file back into the flow. Use another Javascript component to delete the file after it no longer required.

If you use CSV format, you will be able read the original file line by line, modify each line and store it back, so this solution will not consume large amount of memory.

My tests shows that this approach is about 100 times faster comparing with Write or WriteCollection functions. Adobe lacking library to parse or crease csv files, so you will have to build your own or adopt some existing one (Node.js module?)

Next, in your case, you don't have to do it at all. You can do your logic inside delivery template.

Lets asume, you targetData has element [Product/@description]

You can use following JSSP code to build up the lists

<%

     var allProducts =["FOOD","BINS & LINERS","BEVERAGES AND SWEETNERS","CATERING SUPPLIES","BATHROOM & KITCHEN PAPER","CLEANING CHEMICALS & EQUIPMENT","APPLIANCES"];

     var existingProducts = []

     for (var i in targetData.Product) {

          existingProducts.push(targetData.Product[i].description)

     }

     var newProducts = allProducts.filter(function(product) {

          for each (var existing in existingProducts) {

               if (existing == product) {

                    return false

               }

          }

          return true

     })

%>

Then just enumerate through the lists to produce required content

HI ShivaDT,

View solution in original post