Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

We can import PX data to the Datamart using a PA Calculation Logican Analytics calculation logic:

  1. Create a PA Calculation Logic an Analytics calculation logic with a Groovy element (set the Calculation Context of this element to Init) similar to this "Competition" PX Category example:

    Code Block
    def target = api.getDatamartRowSet("target")
    def result = api.stream("PX", null /* sort-by*/, 
                            ["sku","attribute1","attribute2","attribute5","attribute7","attribute9","attribute11"], 
                            Filter.equal("name", "Competition"))
     
    while (result.hasNext()) {
       def comp = result.next()
       // to be able to load rows in the DS we need at least the key fields
       if (comp.sku != null && comp.attribute1 != null) {
          def row = ["DateTime":now,
                     "sku": comp.sku,
                     "Competitor" : comp.attribute1,
                     "Price" : comp.attribute2,
                     "ShippingCost" : comp.attribute5,
                     "DataProvider" : comp.attribute7,
                     "Availability" : comp.attribute9,
                     "Relevant" : comp.attribute11]
          target.addRow(row)
       }
    }
    result.close()


  2. Provided you already created an appropriate Data Source to store the data, in the Data Loads tab you can add a Data Load of the type "Calculation" which uses the above logic to load your PX data.


...

This next example is not related to the one before, it only shows in principle how to cache data read from PX table to a global Map

...

A global variable 'sku2Competitor' is created to ensure that the logic is not run multiple times for the same SKN. In the else statement, we set up filters using api.filter("fieldName", value). Then we create an array "competitors" using api.find(String typeCode, int startRow, int maxRows, String sortBy,List<String> fields, Filter... filters) with the filters that we created to find the row in the NamedCompetition PX that has the given Competitor and SKN. The SKN and Competitor are then stored in the global variable.