Skip to Content

Impex Translator - PK conversion not happening, argument type mismatch error

Hi Experts,

When I use custom impex translator, automatic conversion to PK is not happening.

Please see below two impex statements.

INSERT_UPDATE Product;code[unique=true];approvalStatus(code)
;123 ;approved
INSERT_UPDATE Product;code[unique=true];approvalStatus(code)[translator=com.sap.CustomTranslator]
;123 ;1

public class CustomTranslator extends AbstractValueTranslator{

 @Override
 public Object importValue(final String valueExpr, final Item toItem) throws JaloInvalidParameterException
 {
     if(valueExpr == "1")
     {return "approved"};
 }

 @Override
 public String exportValue(final Object value) throws JaloInvalidParameterException
 {
     return value == null ? "" : value.toString();
 }

}

I get this error when I use translator: java.lang.IllegalArgumentException:
Argument mismatch trying to set value 'approved' for attribute de.hybris.platform.catalog.enums.ArticleApprovalStatus

(got java.lang.String, expected de.hybris.platform.catalog.enums.ArticleApprovalStatus)

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Aug 28, 2017 at 10:47 AM

    Hello Experts,

    I found the answer after some research.

    In ImpEx statments, when we use "approvalStatus(code)" - provide any attribute value for a type (here 'code' attribute is provided for type 'approvalStatus' - OOTB translator will translate this value to actual PK (ItemExpressionTranslator will do the translation in this case - well, different translator may be used as per the scenario OOTB).

    In my case, I was using custom translator, hence, I myself have to derive PK from 'code' attribute.

    The solution in such case where we need to alter the attribute value, we can use decorator. For e.g. : INSERT_UPDATE Product;code[unique=true];approvalStatus(code)[cellDecorator=com.sap.CustomDecorator]

    In the CustomDecorator, apply the same logic as I mentioned previously in CustomTranslator. Decorator would be called first, which would alter the attribute value as per the logic in CustomDecorator. Later, translator will be called which would translate it to PK.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 23, 2017 at 03:29 PM

    Hi ,

    In the above impex header you forgot to give the code attribute.so it should be like this "approvalStatus(code)".

    please look into below impex header INSERT_UPDATE Product;code[unique=true];approvalStatus(code)[translator=com.sap.CustomTranslator] ;123 ;1

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 24, 2017 at 07:55 AM

    Hi , Could you please try changing the return line to enum " return ArticleApprovalStatus.APPROVED;"

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.