cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Impex export: Reference a collection type from attribute

thirumalaicb
Explorer
1,845

Hi Experts,

I have checked the forum and could not find any questions related to this. Hence posting it.

I have the below impex export.

"#% impex.setTargetFile( ""language.csv"", true, 1, -1 );"
INSERT_UPDATE Language;active;fallbackLanguages(isocode);isocode[unique=true]
"#% impex.exportItems( ""Language"" , true );"

Please note the fallbackLanguages attribute in the above impex. This is an OOTB attribute and is of type LanguageList. This exports successfully. The values after the export would be something like en,fr.

But, when I reference a collection type from an attribute, like in the impex export below,

"#% impex.setTargetFile( ""custlanguage.csv"", true, 1, -1 );"
INSERT_UPDATE Customer;uid[unique=true];sessionLanguage(fallbackLanguages(isocode))
"#% impex.exportItems( ""Customer"" , true );"

it is throwing an exception as below.

de.hybris.platform.impex.jalo.ImpExException: line 3 at main script: cannot reference type Language via attribute Language.fallbackLanguages since attribute type LanguageList is not supported[HY-0]
	at de.hybris.platform.impex.jalo.exp.Exporter.export(Exporter.java:186)

It is either this is not supported or I do not know the way to do it. Any help would be highly appreciated.

Accepted Solutions (0)

Answers (1)

Answers (1)

geffchang
Active Contributor
0 Kudos

Check out Translators: https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/4ce7b82cbc574456ac197393f88e...

Create a custom translator which extends AbstractValueTranslator and override the exportValue method. Use this translator with the language(list) / collection attribute.

Let me know if the answer helped. If it did, please don't forget to upvote and accept the answer.

thirumalaicb
Explorer
0 Kudos

Thanks for your response. But, what I am trying to achieve here is something different. It is not what you have mentioned. I understand that sessionLanguage is of type LanguageModel and NOT LanguageList.

geffchang
Active Contributor
0 Kudos

thirumalaicb What are you trying to achieve? Anyway, if you are exporting sessionLanguage of Customer, that's the way to do it. Again, Customer.sessionLanguage has only 0 or 1 value. So, you will never get a list.

thirumalaicb
Explorer
0 Kudos

I am not trying to get any of the immediate attribute values of sessionLanguage, i.e. isocode, active, name, etc. If you take another look at my question above, I am trying to export the value of fallbackLanguages through sessionLanguage attribute. Now, if you ask, why am I trying to get the value of this, it is for a specific use case for my custom item model, however, the example I provided above is using all OOTB item models. The expected outcome for my second impex above should be as below.

dummy1@mailinator.com;en,fr
dummy2@mailinator.com;en,es

I am not sure if this is supported or not, or there is another way to get the value.

geffchang
Active Contributor
0 Kudos

thirumalaicb Your situation now is clearer, compared to how you explained it in the original question. I updated my answer. Have a look at Translators; it might help.

thirumalaicb
Explorer
0 Kudos

@geff.h.n.chang, Thank you for all your comments. Yes, I agree and know about the translators as well. I am looking to see if there is any OOTB provided before writing one. Also, the requirement I have is one-off. I am thinking to write one as a last resort making sure it is not possible and only after evaluating the time and effort. Probably I should have clarified even more before.

There is an OOTB translator as CollectionValueTranslator that by default converts value back and forth using both importValue and exportValue methods to provide an appropriate translation if the value is a collection type. As I provided in my first example, this translator does the job for me automatically, and by default, producing the result for fallbackLanguages(isocode) like en,fr if called directly.

Consider this example below. Here, I am getting the shipping country of the user by referencing CustomerModel.defaultShippingAddress.country.isocode.

"#% impex.setTargetFile( ""custlanguage.csv"", true, 1, -1 );"
INSERT_UPDATE Customer;uid[unique=true];defaultShipmentAddress(country(isocode))
"#% impex.exportItems( ""Customer"" , true );"

This gives me a response as below and is taken care of OOTB as well.

dummy1@mailinator.com;IN
dummy2@mailinator.com;IN

On the other hand, if I tried to reference a collection type as in CustomerModel.sessionLanguage.fallbackLanguages.isocode to get the values like en,fr, it is not working. Kindly let me know if there is anything provided OOTB.