Search code examples
biztalkbiztalk-mapper

BizTalk Mapping: How to show a parent record once only if there are 1 or more child records. Otherwise, do not show parent record


I would like to show a parent record only if one or more child records have values. Otherwise, I do not want the parent record to show up in the output at all. If this is the input

<PO_ALLOWANCES_CHARGES>
    <ALLOW_CHARGE>
        <TYPE/>
        <CODE/>
        <PERCENTQUALIFIER/>
        <PERCENT/>
        <RATE/>
        <METHODOFHANDLING/>
        <DESCRIPTION/>
        <AMOUNT/>
    </ALLOW_CHARGE>
</PO_ALLOWANCES_CHARGES>

Then I would like there to be no output

If this is the input

<PO_ALLOWANCES_CHARGES>
    <ALLOW_CHARGE>
        <TYPE>A</TYPE>
        <CODE>ABCD</CODE>
        <PERCENTQUALIFIER>A</PERCENTQUALIFIER>
        <PERCENT>14.598</PERCENT>
        <RATE>18.54</RATE>
        <METHODOFHANDLING>AB</METHODOFHANDLING>
        <DESCRIPTION>TEST Allow Charge Desc</DESCRIPTION>
        <AMOUNT>104.52</AMOUNT>
    </ALLOW_CHARGE>
        <ALLOW_CHARGE>
        <TYPE>B</TYPE>
        <CODE>BCDE</CODE>
        <PERCENTQUALIFIER>B</PERCENTQUALIFIER>
        <PERCENT>24.598</PERCENT>
        <RATE>28.54</RATE>
        <METHODOFHANDLING>BC</METHODOFHANDLING>
        <DESCRIPTION>TEST Allow Charge Desc 02</DESCRIPTION>
        <AMOUNT>204.52</AMOUNT>
    </ALLOW_CHARGE>
</PO_ALLOWANCES_CHARGES>

Then I would like this to be the output

<ns0:POAllowAndCharges>
    <ns3:POAckAllowAndChargeType>
        <ns3:ChargeId>1</ns3:ChargeId>
        <ns3:ChargeType>A</ns3:ChargeType>
        <ns3:ChargeCode>ABCD</ns3:ChargeCode>
        <ns3:PctQualifier>A</ns3:PctQualifier>
        <ns3:Pct>14.598</ns3:Pct>
        <ns3:Rate>18.54</ns3:Rate>
        <ns3:MethodOfHandling>AB</ns3:MethodOfHandling>
        <ns3:ChargeDesc>TEST Allow Charge Desc</ns3:ChargeDesc>
        <ns3:Amount>104.52</ns3:Amount>
    </ns3:POAckAllowAndChargeType>
    <ns3:POAckAllowAndChargeType>
        <ns3:ChargeId>2</ns3:ChargeId>
        <ns3:ChargeType>B</ns3:ChargeType>
        <ns3:ChargeCode>BCDE</ns3:ChargeCode>
        ns3:PctQualifier>B</ns3:PctQualifier>
        <ns3:Pct>24.598</ns3:Pct>
        <ns3:Rate>28.54</ns3:Rate>
        <ns3:MethodOfHandling>BC</ns3:MethodOfHandling>
        <ns3:ChargeDesc>TEST Allow Charge Desc 02</ns3:ChargeDesc>
        <ns3:Amount>204.52</ns3:Amount>
    </ns3:POAckAllowAndChargeType>
</ns0:POAllowAndCharges>

With this mapping, I get the proper output if there are child records and values. However, the output contains the parent record <ns0:POAllowAndCharges> With this mapping, I get the proper output if there are child records and values. However, the output contains the parent record  <ns0:POAllowAndCharges />

With this mapping, there is no parent record if there are not child records or values but the output is not correct if there are values With this mapping, there is no parent record if there are not child records or values but the output is not correct if there are values

This is the output if with the second mapping if there are child records and values

    <ns0:POAllowAndCharges>
        <ns3:POAckAllowAndChargeType>
            <ns3:ChargeId>1</ns3:ChargeId>
            <ns3:ChargeType>A</ns3:ChargeType>
            <ns3:ChargeCode>ABCD</ns3:ChargeCode>
            <ns3:PctQualifier>A</ns3:PctQualifier>
            <ns3:Pct>14.598</ns3:Pct>
            <ns3:Rate>18.54</ns3:Rate>
            <ns3:MethodOfHandling>AB</ns3:MethodOfHandling>
            <ns3:ChargeDesc>TEST Allow Charge Desc</ns3:ChargeDesc>
            <ns3:Amount>104.52</ns3:Amount>
        </ns3:POAckAllowAndChargeType>
    </ns0:POAllowAndCharges>
    <ns0:POAllowAndCharges>
        <ns3:POAckAllowAndChargeType>
            <ns3:ChargeId>2</ns3:ChargeId>
            <ns3:ChargeType>B</ns3:ChargeType>
            <ns3:ChargeCode>BCDE</ns3:ChargeCode>
            <ns3:PctQualifier>B</ns3:PctQualifier>
            <ns3:Pct>24.598</ns3:Pct>
            <ns3:Rate>28.54</ns3:Rate>
            <ns3:MethodOfHandling>BC</ns3:MethodOfHandling>
            <ns3:ChargeDesc>TEST Allow Charge Desc 02</ns3:ChargeDesc>
            <ns3:Amount>204.52</ns3:Amount>
        </ns3:POAckAllowAndChargeType>
    </ns0:POAllowAndCharges>

It causes the parent record to be duplicated with each iteration of the child records. I would like all of the child records to be contained within the one Parent record.

Does anyone know how I might achieve something like this?


Solution

  • You were nearly there

    1. You don't need the looping functoid, it already knows to loop.
    2. You need to have the Cumulative Concatenate Functoid for the POAllowAndCharges

    ![BizTalk Map