Product: Mapping Manager
Article Link: http://help.truecommerce.com/en/articles/9925360-xpath-if-entityinternalid-6312-then-6312-1-else-entityinternalid
xPath Sample
if(//entityInternalId[.='6312']) then('6312-1') else (//entityInternalId)
This example assumes that you have placed the xPath Function within a token under the Invoice row within Mapping Manager.
XML Sample - Match Found
<Invoice>
<internalId>897747</internalId>
<externalId/>
<createdDate>6/19/2023 4:33:22 PM</createdDate>
<lastModifiedDate>2/14/2024 2:13:09 PM</lastModifiedDate>
<entityInternalId>6312</entityInternalId>
<entityNormalizedName>679 : 631</entityNormalizedName>
<tranDate>6/19/2023 3:00:00 AM</tranDate>
<tranId>INV15398</tranId>
<createdFrom>Sales Order #SO11229</createdFrom>
</Invoice>
Result: 6312-1
In this example - since the entityInternalId equals 6312 - the xPath will return the 'then' portion which is hardcoded as 6312-1
XML Sample - No Match
<Invoice>
<internalId>897747</internalId>
<externalId/>
<createdDate>6/19/2023 4:33:22 PM</createdDate>
<lastModifiedDate>2/14/2024 2:13:09 PM</lastModifiedDate>
<entityInternalId>6511</entityInternalId>
<entityNormalizedName>679 : 631</entityNormalizedName>
<tranDate>6/19/2023 3:00:00 AM</tranDate>
<tranId>INV15398</tranId>
<createdFrom>Sales Order #SO11229</createdFrom>
</Invoice>
Result: 6511
In this example - entityInternalId does not match and as such will return whatever value is inside entityInternalId (6511) since we're pulling the field value, rather than hard-coding it.
Notes
By using //entityInternalId[.='6312'] we are attempting to select specifically the entityInternalId with a value of 6312
When wrapped inside an if() - will be parsed as a boolean (yes/no) value
The period within the square brackets represents selecting the node itself
We then use the equals (=) sign to check the value
We use single quotes to ensure we're checking the value exactly
rev 9/26/2024