XTK session write | Community
Skip to main content
shivaDT
New Participant
April 20, 2016
Solved

XTK session write

  • April 20, 2016
  • 13 replies
  • 17660 views

Hi Team ,

could you please advise ,if there is something wrong with the below script ..

I have tried to use it and its not working ...

please suggest ..

xtk.session.Write(<enrich4
xtkschema="temp:enrich4" _key="@id" id={responder.@id} > <Product2
description={secondArray[1]}/> <Product3
description={secondArray[2]}/></enrich4>);

regards

shiva

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by DimaKudryavtsev

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,

13 replies

shivaDT
shivaDTAuthor
New Participant
May 3, 2016

Hi Linda,

Thanks for your response ..

Below is the full context behind this XML script ..

I have a workflow which identifies the products purchased by each customer   and ranks the spend on each product.

Then there is a delivery ,which presents the products as per their spend (Rank) and the products they haven’t purchased from a list (below are the products).

The products I am looking for are : ("FOOD","BINS & LINERS","BEVERAGES AND SWEETNERS","CATERING SUPPLIES","BATHROOM & KITCHEN PAPER","CLEANING CHEMICALS & EQUIPMENT","APPLIANCES")

Example: a customer might only purchase three products FOOD, CATERING SUPPLIES & CLEANING CHEMICALS & EQUIPMENT ..  the delivery needs to have these three products as well as the remaining products he has not purchased from the list .

This customer has purchased three products and I have the order , what I trying to do with the JS is : fill in the blanks with the remaining products ..

So customers remaining products should be BINS & LINERS, CATERING SUPPLIES, CLEANING CHEMICALS & EQUIPMENT, APPLIANCES 

I am using an array in the JS to do this , the array works as per the requirements .. however I am unable to write the values which are stored in the array back in to the variables..

Linda_Stinson
Employee
May 2, 2016

Also, it appears you are attempting to query the temporary worktable in a workflow. Is that the case, and do you mind sharing the reason for doing so?

Linda_Stinson
Employee
May 2, 2016

Shiva, can you share the error that you are getting? If you are running this in a workflow (good idea for testing) you can activate the workflow property to log SQL queries in the journal.

Linda