AnsweredAssumed Answered

How to combine portions of XML

Question asked by cegbert328645 on Jun 28, 2018

I am sending Opportunities and Line Items from Salesforce to QuickBooks. Here is the simplified version of the XML coming from Salesforce:

 

<Opportunity>
  <QB_Sales_Order_Txn_Id__c>Order1</QB_Sales_Order_Txn_Id__c>
  <OpportunityLineItems>
    <OpportunityLineItem>
      <TxnId__c>GroupLine1</TxnId__c>
      <GroupTxnLineId__c>Group1</GroupTxnLineId__c>
    </OpportunityLineItem>
    <OpportunityLineItem>
      <TxnId__c>GroupLine2</TxnId__c>
      <GroupTxnLineId__c>Group1</GroupTxnLineId__c>
    </OpportunityLineItem>
    <OpportunityLineItem>
      <TxnId__c>GroupLine3</TxnId__c>
      <GroupTxnLineId__c>Group1</GroupTxnLineId__c>
    </OpportunityLineItem>
    <OpportunityLineItem>
      <TxnId__c>Line1</TxnId__c>
      <GroupTxnLineId__c />
    </OpportunityLineItem>
  </OpportunityLineItems>
</Opportunity>

 

After going through the map, here is what I end up with for the QuickBooks XML:

 

<SalesOrderModRq>
     <SalesOrderMod>
          <TxnID>Order1</TxnID>
          <SalesOrderLineMod>
               <TxnLineID>Line1</TxnLineID>
          </SalesOrderLineMod>
          <SalesOrderLineGroupMod>
               <TxnLineID>Group1</TxnLineID>
               <SalesOrderLineMod>
                    <TxnLineID>GroupLine1</TxnLineID>
               </SalesOrderLineMod>
          </SalesOrderLineGroupMod>
          <SalesOrderLineGroupMod>
               <TxnLineID>Group1</TxnLineID>
               <SalesOrderLineMod>
                    <TxnLineID>GroupLine2</TxnLineID>
               </SalesOrderLineMod>
          </SalesOrderLineGroupMod>
          <SalesOrderLineGroupMod>
               <TxnLineID>Group1</TxnLineID>
               <SalesOrderLineMod>
                    <TxnLineID>GroupLine3</TxnLineID>
               </SalesOrderLineMod>
          </SalesOrderLineGroupMod>
     </SalesOrderMod>
</SalesOrderModRq>

 

See how all the Group Items that had the same GroupTxnLineId__c number ended up in separate groups in the XML?

 

Here is what I am trying to achieve:

 

<SalesOrderModRq>
     <SalesOrderMod>
          <TxnID>Order1</TxnID>
          <SalesOrderLineMod>
               <TxnLineID>Line1</TxnLineID>
          </SalesOrderLineMod>
          <SalesOrderLineGroupMod>
               <TxnLineID>Group1</TxnLineID>
               <SalesOrderLineMod>
                    <TxnLineID>GroupLine1</TxnLineID>
               </SalesOrderLineMod>
               <SalesOrderLineMod>
                    <TxnLineID>GroupLine2</TxnLineID>
               </SalesOrderLineMod>
               <SalesOrderLineMod>
                    <TxnLineID>GroupLine3</TxnLineID>
               </SalesOrderLineMod>
          </SalesOrderLineGroupMod>
     </SalesOrderMod>
</SalesOrderModRq>

 

This way each item in the group ends up under a single node for Group1.

 

This has proven to be difficult given that the group in Salesforce is determined by all records with the same GroupTxnLineId__c value. Any guidance would be much appreciated.

 

Thank you,

Chandler

Outcomes