08-31-2021 05:03 AM
Hi,
I want to write this code in expression snaplogic.
I need to map TestID.
<xsl:variable name=“TestID”>
<xsl:if test=“exists(node()/IDOC/A1[VW=‘F’]/NO)”>
<xsl:copy-of select=“node()/IDOC/A1[VW=‘F’]/NO”>
</xsl:copy-of>
</xsl:if>
<xsl:if test=“not(exists(node()/IDOC/A1[VW=‘F’]/NO))”>
<xsl:copy-of select=“node()/IDOC/A1[VW=‘F’]/NP”>
</xsl:copy-of>
</xsl:if>
</xsl:variable>
How do I do it?
Solved! Go to Solution.
09-01-2021 01:22 AM
Hi @Sahil,
Here are two expressions, I was not sure because it is array does always will have only one VW that contains ‘F’ in the value.
First expression. Finds all NO or NP that contains ‘F’ in VW field.
$Data.IDOC.A1.filter(e => e.get('VW').contains('F')).map(x => x.get('NO') != null ? x.NO : x.NP)
But I think that the second expression is more correct. This expression finds the first one element in the array that contains ‘F’ in VW, and returns NO if exist or else NP.
$Data.IDOC.A1.find(e => e.get('VW').contains('F')).get('NO', $Data.IDOC.A1.find(e => e.get('VW').contains('F')).get('NP'))
By default this expression return null, and if you want something else you can add second parameter in the get method for default values.
Ex: .get('NP', "Default")
Regards,
Viktor
09-01-2021 01:22 AM
Hi @Sahil,
Here are two expressions, I was not sure because it is array does always will have only one VW that contains ‘F’ in the value.
First expression. Finds all NO or NP that contains ‘F’ in VW field.
$Data.IDOC.A1.filter(e => e.get('VW').contains('F')).map(x => x.get('NO') != null ? x.NO : x.NP)
But I think that the second expression is more correct. This expression finds the first one element in the array that contains ‘F’ in VW, and returns NO if exist or else NP.
$Data.IDOC.A1.find(e => e.get('VW').contains('F')).get('NO', $Data.IDOC.A1.find(e => e.get('VW').contains('F')).get('NP'))
By default this expression return null, and if you want something else you can add second parameter in the get method for default values.
Ex: .get('NP', "Default")
Regards,
Viktor