cancel
Showing results for 
Search instead for 
Did you mean: 

Need to escape custom session parameters importing SearchRestrictions by impex?

0 Kudos
513

Hi all, on Hybris 6.4 (5.7 as well) we're trying to import a SearchRestriction using Impex, to create a custom restriction on a dedicated user setted as sessionUser on a products sync job (in 5.7, I knew, was the only way to apply restrictions on sync jobs) to just sync some specific products. The restriction query is something like:

EXISTS ({{ SELECT DISTINCT {p.pk} FROM { Product AS p } WHERE {p.pk}={item.pk} AND {p.customAttribute} in ( ?session.currentCronJob.customAttributeList ) }})

customAttributeList is a custom field setted in a custom sync Cronjob instance (list of strings). customAttribute is a string identifying a custom parameter.

During impex import using hac (but using project data too), we have the following error: Exception : line 2: cannot create SearchRestriction with values ItemAttributeMap[...] due to no attribute ImpExImportJob.customAttributeList found transaction rolled back because it has been marked as rollback-only

It seems that during impex import, the query is evaluated trying to replace parameters with valid plain (current session) values. Is this the correct behaviour? Shouldn't the query not to be evaluated during import?

Now questions are: How can we successfully import this kind of SearchRestriction using impex? Has any option which let us configure impex engine to not evaluate query parameters during impex import? Any other option to escape parameters during import?

Ref. https://help.hybris.com/6.4.0/hcd/8c428f8286691014970ceee87aa01605.html#restrictions-creatingrestric... https://help.hybris.com/6.4.0/hcd/8b9ce4868669101499b2f0f25ef9395f.html#cronjob-technicalguide-using...

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

The problem occurs when parameters "session.currentJob" or "session.currentCronJob" are used, Please, just for test, are you able to import this impex?

 INSERT_UPDATE User ; uid[unique=true] ; name[en]
 ; testUser; testUser
 
 INSERT_UPDATE SearchRestriction ; code[unique=true] ; name[lang=de] ; name[lang=en] ; principal(UID) ; restrictedType(code) ; active ; generate ; query                         ; test ; test ; test ;  testUser ; Product  ; false  ; false    ; "EXISTS ({{ SELECT DISTINCT {p.pk} FROM { Product AS p } WHERE {p.pk}={item.pk} AND {p.customAttribute} in ( ?session.currentCronJob.customAttributeList ) }})"

Do you receive my same error?

0 Kudos

Hi , thanks for your reply, I imported using backoffice the new restriction (which worked perfectly) and tried to export it using hac exporting features (using mode: export_reimport_strict) to check if any escape character was used, but just double quotes was added to my query value field (in the impex I already used double quotes) . Reimporting it causes the same error. The only way I can import this kind of searchRestriction (with session parameters), at the moment, is creating them directly from backoffice. If you have any idea please share it! :D

former_member1002389
Active Participant
0 Kudos

Check two settings while importing. One Legacy Mode. If session attributes are converting at service layer, then enable legacy mode ON to bypass service layer. Second, check Code Execution, is this enabled or disabled. I tried below impex and worked perfectly for me. INSERT_UPDATE SearchRestriction;code[unique=true];query; ;Frontend_StockNotExpired;"({expired} IS NULL OR {expired} > ?session.user.currentDate)";

0 Kudos

I'm importing without using any of these flags: ![alt text][1] [1]: /storage/temp/9708-screen-shot-2017-10-11-at-181606.png I was not able to import you impex to to the incomplete header due to "..target type SearchRestriction is not permitted by current header - type SearchRestriction requires missing columns [principal, restrictedType, generate]..".

former_member1002389
Active Participant
0 Kudos

mine one is already there. I just update it. and for yours one try selecting legacy mode ON and import it.

former_member1002389
Active Participant
0 Kudos

export the existing one and then change your values and reimport it again. you may find the escape character there.