Skip to Content
avatar image
Former Member

Import XML with multiple items using vb.net

Hi experts,

I was able to add a single item to SAPB1 via a vb.net using an XML, however, I can't seem to use the same XML structure to add multiple items or even two items, below is TEST 1 and TEST 2, only TEST 1 is added to SAPB1.

 oSO = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
 oSO.Browser.ReadXml("C:\TEMP\sales-order2.xml", 0)
 oSO = oCompany.GetBusinessObjectFromXML("C:\TEMP\sales-order2.xml", 0)
 oCompany.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode
 lRetCode = oSO.Add()
<?xml version="1.0" encoding="UTF-16" ?>
<BOM>
  <BO>
    <AdmInfo>
      <Object>17</Object>
    </AdmInfo>
    <ORDR>
      <row>
        <CardCode>1</CardCode>
        <DocDueDate>20171120</DocDueDate>
        <NumAtCard>344312</NumAtCard> 
       <Comments>
         TEST 1
       </Comments>
      </row>
    </ORDR>
    <RDR1>
      <row>
        <ItemCode>1213</ItemCode>     
        <Quantity>1</Quantity>
      </row>
      <row>
        <ItemCode>2100</ItemCode>     
        <Quantity>1</Quantity>
      </row>
    </RDR1>
    <ORDR>
      <row>
        <CardCode>1</CardCode>
        <DocDueDate>20171120</DocDueDate>
        <NumAtCard>344313</NumAtCard>
        <Comments>
           TEST 2
        </Comments>
      </row>
    </ORDR>
    <RDR1>
      <row>
        <ItemCode>1213</ItemCode>
        <Quantity>1</Quantity>
      </row>
      <row>
        <ItemCode>2100</ItemCode>
        <Quantity>1</Quantity>
      </row>
    </RDR1>
    <OSRI />
    <OIBT />
  </BO>
</BOM>

Add comment
10|10000 characters needed characters exceeded

  • Former Member

    Did you received any error upon uploading XML?

  • Former Member Former Member

    Thanks, Former Member, no error received, the code runs okay but my issue is it only adds the first item from the XML, I have also learned that ReadXML only works by getting the first item from the XML, so what I'm trying to do now is to loop that content of the XML, so it will read every lines of the XML file. Is there any reference you can share with me on how can I do this?

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Nov 28, 2017 at 04:03 PM

    Below code is when I duplicate BOM(Bill of Materials) using XML. It saves all the lines:

    Dim oProduction As SAPbobsCOM.ProductTrees
    oProduction = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductTrees)
    
    If (oProduction.GetByKey(cbTranType.Selected.Value)) Then
        If isUpdate Then
            GoTo Created
        End If
    
        Dim Filename As String = System.IO.Path.GetTempFileName()
    
        'Export production
        Dim oXmlDoc As New XmlDocument()
        oXmlDoc.LoadXml(oProduction.GetAsXML())
        oXmlDoc.SelectSingleNode("//Code").InnerText = oItemCode
        For Each oNode As XmlNode In oXmlDoc.SelectNodes("//Father")
            oNode.InnerText = oItemCode
        Next
    
        oXmlDoc.Save(Filename)
    
        '"Save duplicate production
        Dim newProduction As SAPbobsCOM.ProductTrees
        newProduction = oCompany.GetBusinessObjectFromXML(Filename, 0)
    
        If newProduction.Add <> 0 Then
            SBO_Application.MessageBox(oCompany.GetLastErrorDescription)
            SAPClass.SetMessage(oCompany.GetLastErrorDescription, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
            Return False
        End If
    
    End If
    Add comment
    10|10000 characters needed characters exceeded