CREAR DOCUMENTO EN SAPB1 DESDE UN XML

Code with Edd

COMO CREAR UN DOCUMENTO EN SAPB1 MEDIANTE UN ARCHIVO XML UTILIZANDO DI API.

SAPbobsCOM.Documents oDocto = null;
oDocto = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oQuotations);

try
{
    oCompany.XmlExportType = BoXmlExportTypes.xet_ExportImportMode;
    if (oCompany.GetXMLobjectType(@"C:\XML\MiArchivoXML.xml", 0) == SAPbobsCOM.BoObjectTypes.oQuotations)
    {
        oDocto.Browser.ReadXml(@"C:\XML\MiArchivoXML.xml", 0);

        int lRetCode = oDocto.Add();
        if (lRetCode != 0)
        {
            int lErrCode;
            string sErrMsg;
            oCompany.GetLastError(out lErrCode, out sErrMsg);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oDocto);
            
            return new AddResponse { Success = false, DocNum = "", Messages = lErrCode + " " + sErrMsg };
        }
        else
        {
            var numberDocument = oCompany.GetNewObjectKey();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(oDocto);

            return new AddResponse { Success = true, DocNum = numberDocument, Messages = "Documento creado correctamente." };
        }
    }
    else
    {
        return new AddResponse { Success = false, DocNum = "", Messages = "XML Contains not supported Items" };
    }
}
catch (Exception ex)
{
    System.Runtime.InteropServices.Marshal.ReleaseComObject(oDocto);
    return new AddResponse { Success = false, DocNum = "", Messages = ex.Message };
}

El archivo XML debe de seguir las reglas que dicta SAPB1 en su archivo de ayuda SAP Business One SDK – Help Center.

Ejemplo del archivo XML.

<?xml version=\"1.0\" encoding=\"UTF-16\"?><BOM><BO><AdmInfo><Object>23</Object><Version>2</Version></AdmInfo><Documents><row><DocDate>20201127</DocDate><DocDueDate>20201130</DocDueDate><CardCode>C00690</CardCode><DocCurrency>MXP</DocCurrency><Comments>Pruebas desde objecto XML</Comments><Confirmed>tYES</Confirmed></row></Documents><Document_Lines><row><LineNum>0</LineNum><ItemCode>0-001</ItemCode><Quantity>6</Quantity><Price>21.89</Price><Currency>MXP</Currency><WarehouseCode>AGDL</WarehouseCode><TaxCode>A0</TaxCode><UnitPrice>21.89</UnitPrice><MeasureUnit>PZA</MeasureUnit></row><row><LineNum>1</LineNum><ItemCode>0-002</ItemCode><Quantity>3</Quantity><Price>20.16</Price><UnitPrice>20.16</UnitPrice><Currency>MXP</Currency><WarehouseCode>AGDL</WarehouseCode><TaxCode>A0</TaxCode><MeasureUnit>PZA</MeasureUnit></row><row><LineNum>2</LineNum><ItemCode>0-031</ItemCode><Quantity>7</Quantity><Price>22.16</Price><UnitPrice>22.16</UnitPrice><Currency>MXP</Currency><WarehouseCode>AGDL</WarehouseCode><TaxCode>A0</TaxCode><MeasureUnit>PZA</MeasureUnit></row></Document_Lines></BO></BOM>

Referencia:

SAP Business One SDK – Help Center
https://help.sap.com/viewer/product/SAP_BUSINESS_ONE/9.3/es-ES

CREAR DOCUMENTO EN SAPB1 DESDE UN XML
Web | + posts

Full Stack Web Developer && SDK SAPB1 Developer.

Melómano, Gamer (Xbox), Comprador compulsivo de Amazon y Posiblemente con TDAH.

Scroll hacia arriba