Can different records go to different branches

Question: how can I, when receiving multiple records through a webhook, send them through the flow one at a time or branch off when one of the records is incorrect?

 

I have a webhook that is receiving shipment data to send load information to our TMS which comes through a WebHook with multiple records. When a record comes through that is missing data, I want to branch off that bad record. 

Originally, instead of a webhook, we were using individual files. In that scenario, if one file had missing data, then it would error and the other files would process successfully.

Now, we're switching to a series of API's due to how the data comes out of the WMS software. For that process, I have one flow that is pulling the data from the WMS (that looks like the below) and then sending parsed contents of the <pXMLDoc> into a webhook process flow. 

Since it's coming through a WebHook, I'm not able to break the records up and send them one at a time from what I can tell, but that's what I need it to do. I have all of the flow steps set to “Parse One to Many” but the branch received all of the records at once. 

0

Comments

3 comments
Date Votes
  • Jack Harris this is possible to do, but you'll need a preSavePage script. For other sources, like HTTP and FTP, they have a “path to records” field, which is what you're needing in this case, however webhook sources don't have this field. So in your preSavePage script, you take each record which could be 2, then output 3. Can you send a complete XML sample? Here is a sample script though to give direction:

    function preSavePage(options) {
      const updatedData = options.data.map(record => {
        if (record['soap:Body'] && record['soap:Body'].GetOrderStatusDetail_Result && record['soap:Body'].GetOrderStatusDetail_Result.pxXMLDoc) {
          const pxXMLDoc = record['soap:Body'].GetOrderStatusDetail_Result.pxXMLDoc;
          if (Array.isArray(pxXMLDoc)) {
            return pxXMLDoc.map(doc => {
              return doc;
            });
          } else {
            return pxXMLDoc;
          }
        }
        return record;
      }).flat();
    
      return updatedData;
    }
    0
  • Jack Harris you're preSavePage script on the lookup would be this. Notice it checks for array or object because with XML parsing if it only sent 1 confirmation, then it would parse as an object, but if there are multiple then it parses into an Array of multiple.

    function preSavePage (options) {
      const newData = [];
      options.data.forEach(record => {
        if (Array.isArray(record.ShipmentConfirmationAdvice)) {
          record.ShipmentConfirmationAdvice.forEach(advice => {
            newData.push(advice);
          });
        } else {
          newData.push(record.ShipmentConfirmationAdvice);
        }
      });
      return {
        data: newData,
        errors: options.errors,
        abort: false,
        newErrorsAndRetryData: []
      };
    }

     

    For the given XML:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Transaction Type="Shipment Confirmation Advice" xmlns="urn:microsoft-dynamics-nav/xmlports/x50001">
      <ShipmentConfirmationAdvice>
        <DepositorCode>XXX</DepositorCode>
        <OrderRefNumber>ANON123456</OrderRefNumber>
        <PurchOrderNumber />
        <ShipmentID>SHIP12345</ShipmentID>
        <OrderDate>01/16/2025</OrderDate>
        <ShipDate>01/20/2025</ShipDate>
        <ExpDeliveryDate>01/22/2025</ExpDeliveryDate>
        <CancelDate />
        <ShipTo>
          <ShipToCode>ANONCODE</ShipToCode>
          <ShipToName>ANON NAME</ShipToName>
          <ShipToName2 />
          <ShipToAddr1>ANON ADDRESS</ShipToAddr1>
          <ShipToAddr2 />
          <ShipToCity>ANON CITY</ShipToCity>
          <ShipToState>XX</ShipToState>
          <ShipToZip>00000</ShipToZip>
          <ShipToCountry>XX</ShipToCountry>
        </ShipTo>
        <ShipFrom>
          <ShipFromCode>ANON</ShipFromCode>
          <ShipFromName>ANON NAME</ShipFromName>
        </ShipFrom>
        <Carrier>
          <CarrierCode>ANONCARRIER</CarrierCode>
          <CarrierName>ANON CARRIER</CarrierName>
        </Carrier>
        <ProNumber />
        <Warehouse>WHXX</Warehouse>
        <ShipmentMethodCode>ANON</ShipmentMethodCode>
        <FreightBillType>0</FreightBillType>
        <FreightBillTo>
          <FrtBillToCode>ANONCODE</FrtBillToCode>
          <FrtBillToName>ANON NAME</FrtBillToName>
          <FrtBillToAddr1>ANON ADDRESS</FrtBillToAddr1>
          <FrtBillToAddr2 />
          <FrtBillToCity>ANON CITY</FrtBillToCity>
          <FrtBillToState>XX</FrtBillToState>
          <FrtBillToZip>00000</FrtBillToZip>
          <FrtBillToCountry>XX</FrtBillToCountry>
        </FreightBillTo>
        <FreightCost>0.00</FreightCost>
        <HdrUser1 />
        <HdrUser2 />
        <HdrUser3 />
        <HdrUser4 />
        <HdrUser5>XXX</HdrUser5>
        <OrderStatus>ANON</OrderStatus>
        <TotalQtyOrdered>0</TotalQtyOrdered>
        <GrsWeight>0</GrsWeight>
        <NetWeight>0.00</NetWeight>
        <ShipLine>
          <ItemNumber>ITEM0001</ItemNumber>
          <QtyOrdered>40</QtyOrdered>
          <QtyShipped>0</QtyShipped>
          <UOM>ANON</UOM>
          <ItemDesc1>ANON ITEM</ItemDesc1>
          <ItemDesc2 />
          <Lot />
          <LineReference />
          <SubPart1Number />
          <SubPart2Number />
          <AltItemNo />
          <SerialNumber />
          <NMFCCode />
          <FreightClass>XX</FreightClass>
          <LineUser1 />
          <LineUser2 />
          <LineUser3 />
          <LineUser4 />
          <LineUser5 />
          <LGrsWeight>0000.0</LGrsWeight>
          <LNetWeight />
          <GroupID />
          <CodeDate />
        </ShipLine>
      </ShipmentConfirmationAdvice>
    
    </Transaction>
    
    1
  • Thank you so very much. This is going to come greatly in handy for us moving forward!

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post