javasap-commerce-cloudimpex

How do I import current date-time as MMM d, y, h:mm:ss in hotfolder Impex config?


Into a Hybris database I'm trying to insert cart entries as current date-time. When testing the Impex on the HAC I get the same error as from the cronjobs logs:

$coupon=appliedCouponCodes[collection-delimiter=|][merge=true]
$user=user[unique=true,translator=com.mycompanyname.core.dataimport.translator.MyCompanyNameOrgCartCustomerFromWebOrgId]
$store=store[unique=true,translator=com.mycompanyname.core.dataimport.translator.MyCompanyNameQuoteSiteToStoreTranslator]

#% impex.definitions.put("$currentDate", java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("MMM d, yyyy, h:mm:ss a")))

INSERT_UPDATE Cart;code[unique=true];$user;site(uid);$store;date[dateformat="MMM d, yyyy hh:mm:ss a"][default="Mar 2, 2004, 1:24:33 p"];currency(isocode)[default=CAD]
;"2300001";"100005_w";"ca.mycompanybasesite.com";"ca.mycompanybasestore.com";$currentDate

When I hard-code the date-time value or keep it blank to get the default value it will run the Impex which suggests there are no dependencies on the translator. The error only occurs when I use the variable $currentDate:

INSERT_UPDATE Cart;code[unique=true];user[unique=true,translator=com.avantor.core.dataimport.translator.AvantorOrgCartCustomerFromWebOrgId];site(uid);store[unique=true,translator=com.avantor.core.dataimport.translator.AvantorQuoteSiteToStoreTranslator];"date[dateformat=""MMM dd, yyyy hh:mm:ss a""][default=""Mar 2, 2004, 1:24:33 p""]";currency(isocode)[default=CAD]
",,,,cannot parse date '$currentDate' with specified pattern '""MMM d' due to Unparseable date: ""$currentDate""";2300001;100005_w;ca.mycompanybasesite.com;ca.mycompanybasestore.com;$currentDate

I also tried running the line in an online Java compiler:

System.out.println(java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("MMM d, yyyy, h:mm:ss a")))

Which returns Oct 8, 2023, 10:23:41 AM without issues. I tried other date-time formats without luck as well. I also tried formatting the date using this answer (SimpleDateFormat), this, and this, to no avail. I use version 2211.9 of SAP Commerce Cloud.


Solution

  • Try

    #% impex.enableCodeExecution(true)
    #% setAccessibility(true)
    #% impex.definitions.put("$currentDate", new Date())
    
    INSERT_UPDATE Cart;...; date         ;...
                      ;...; $currentDate ;...