cancel
Showing results for 
Search instead for 
Did you mean: 

Import XML with multiple items using vb.net

Former Member
0 Kudos

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>

Former Member
0 Kudos

Did you received any error upon uploading XML?

Former Member
0 Kudos

Thanks, bryan.gomez, 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?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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