cancel
Showing results for 
Search instead for 
Did you mean: 

Custom actions during SAP Commerce hot folder processing

ccronquillo
Explorer
0 Kudos

We're familiar with how hot folder feature happens: A CSV is taken in for processing, an impex is created based on the CSV's data rows, and then data is inserted into the table which corresponds to the configured impex header statement.

What if we need an intermediate checking for the CSV data, which determines whether or not the data (row) should be added into the resulting impex statement? Our use case is that we would want to determine the value of a CSV data row based on some system values. Another is we assess the existence of the value of another data in that row in Backoffice. I'm imagining if we could execute a flexible search in a Java code that does these before the impex gets run in the end.


Any thoughts would be appreciated. 🙂

Accepted Solutions (1)

Accepted Solutions (1)

andyfletcher
Active Contributor

You can put scripting blocks into your impex to run before each line is imported. The `line` variable is a map of field number to value.

e.g.

INSERT_UPDATE Product;code[unique=true];name[lang=en];catalogVersion(catalog(id[default=Default]),version[default=Staged])[unique=true]
"#% beforeEach:
if (""test-2"".equals(line.get(1))) line.clear();
if (""test-3"".equals(line.get(1))) line.put(2, ""TEST 3"");
"
;test-1;Test 1
;test-2;Test 2
;test-3;Test 3

Clearing the line means it doesn't get imported. Putting a new value overwrites the data for that column.
Note you have to escape the quotes by doubling them up. If you set impex.legacy.scripting to false then you can use Groovy too which allows more concise syntax and let's you use single quotes or slashes around strings to avoid escaping.

INSERT_UPDATE Product;code[unique=true];name[lang=en];catalogVersion(catalog(id[default=Default]),version[default=Staged])[unique=true]
"#%groovy% beforeEach: 
if ('test-2'==line[1]) line.clear()
if ('test-3'==line[1]) line[2]=flexibleSearchService.search(/select {pk} from {language} where {isocode}='en'/).result[0].name
"
;test-1;Test 1
;test-2;Test 2
;test-3;Test 3

https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/aa417173fe4a4ba5a473c93eb730a417/640172cbd...

 

ccronquillo
Explorer
0 Kudos
Cool! Thank you so much!

Answers (0)