Logical Existence doesn't work - BizTalk Mapper

936 Views Asked by At

This problem has confounded me for a while now. I have a flat file with segments and tag identifiers. One of the segments is optional. That is fine, but i need logic to determine if this segment exists. If it does not exist i need to do something else. All works as planned if the segment exists. If it doesn't, it appears BizTalk does not even recognize or execute any functoids related to the segment.

Here is the flat file segment: flat file segment map snap And here is my Logical Existence connected to a Logical NOT:

Again, if the segment is completely gone (meaning no flat file xml nodes are created/translated), the Logical Existence does not even execute. I've tried scripts, functoids. I'm becoming convinced this is a bug in the mapper. Any help appreciated.

2

There are 2 best solutions below

1
On

Since your input file is a flat file, the FFDASM is creating an empty node. The test run by Logical Existence evaluates to true on an empty node. Logical String should work here (I was previously thinking it would return true for an empty string but it shouldn't).

However, in this case, I'd probably replace all of that (including the value mapper) with a C# scripting functoid:

public string AllowIfNotEmpty(string test, string output)
{
    if (!string.IsNullOrWhiteSpace(test))
        return output;
    return "";
}

Give it the input of the node currently linked to Logical String first, and the second input to your Value Mapping(flattening) second, and output it directly to your destination node.

You could put that into a helper assembly if it's something you use in multiple places.

If you wanted to keep it as XSLT, you could do a custom call template:

<xsl:template name="OutputIfNotEmpty">
    <xsl:param name="test" />
    <xsl:param name="output" />
    <xsl:if test="normalize-space($test) != ''">
        <xsl:element name="OutputElementName">
            <xsl:value-of select="$output" />
        </xsl:element>
    </xsl:if>        
</xsl:template>
0
On

Try using the Value Mapping functoid instead of the Value Mapping (Flattening) functoid.

Also ensure that the parameters of the Value Mapping functoids are in the correct order. The logical operator must be the first parameter. Sometimes the parameters go out of order and the functoid stops working as expected.