on ‎2018 Nov 03 1:31 AM
Dear experts,
here is my problem. I have two items - both have no explicit unique attributes defined and they are connected by a relation with partof=true for the dependent item type. Is it possible to create an IMPEX that would insert their instances? If so, could please provide an example of such impex?
To make it more concrete here is the simplified items definition:
<relation code="InboundRequest2InboundRequestError" localized="false">
<sourceElement type="InboundRequest" qualifier="inboundRequest" cardinality="one" />
<targetElement type="InboundRequestError" qualifier="errors" cardinality="many" collectiontype="set">
<modifiers partof="true" />
</targetElement>
</relation>
...
<itemtype code="InboundRequest">
<attributes>
<attribute qualifier="type" type="java.lang.String">
<modifiers optional="false" />
</attribute>
</attributes>
</itemtype>
<itemtype code="InboundRequestError">
<attributes>
<attribute qualifier="code" type="java.lang.String">
<modifiers optional="false" />
</attribute>
<attribute qualifier="message" type="java.lang.String">
<modifiers optional="false" />
</attribute>
</attributes>
</itemtype>
I skipped many details in this example - this is just a concept. Although the error has field code, it's the error code, which is not unique. I have nothing to bite except the PK. Is it possible to refer to the PK of the InboundRequest as I create InboundRequestErrors in the impex?
Request clarification before answering.
You should be able to do this with DocumentId https://help.hybris.com/1808/hcd/1c8f5bebdc6e434782ff0cfdb0ca1847.html#loio4f654a1a8e6e4429a83eb868a...
e.g. something like this?
INSERT InboundRequest;type;&Request
;dostuff;req1
;otherstuff;req2
INSERT InboundRequestError;code;message;inboundRequest(&Request)
;101;Stuff broke;req1
;101;Stuff really broken;req2
;102;WTF?;req2
This assumes that you are creating the InboundRequest and InboundRequestError in the same impex file.
&Request is effectively a temporary unique reference that only exists for the processing of this file. It doesn't matter what it is, just that it matches up with the corresponding reference in the related type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Andrew,
thanks a lot for the solution. That is exactly the feature I was looking for. I managed to get it working.
I should also recognize for his answer, which unfortunately got deleted. I ended up using his advice for pk[allownull = true, unique = true] because without a unique field the impex did not work.
Thank you both!
INSERT should work without a unique column as you don't need to find a unique row in the database to update.
INSERT_UPDATE or UPDATE would require one though.
I think that by specifying pk as a unique column but passing a null value then it is never doing an update because it is never finding a matching row with a null pk. So it's always an INSERT then.
I.e. these 2 examples would be equivalent.
INSERT_UPDATE InboundRequestError;code;pk[unique=true,allownull=true]
;1
INSERT InboundRequestError;code
;1
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.