Skip to Content
0

ADD INVOICES FROM DI-API USING XML

Jun 23, 2017 at 06:33 PM

102

avatar image
Former Member

I NEED TO ADD BILLS BY THE SAP BO SDK USING THE DI-API AND BELIEVE THIS CODE:

// Connects to the SAP Business One company database.

oCompany.Connect();

MessageBox.Show("CONECTADO..!!");

int count = oCompany.GetXMLelementCount("C:\\temp.xml");

SAPbobsCOM.Documents oJE;

oJE = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);

for (int i = 0; i < count; i++) {

if (oCompany.GetXMLobjectType("C:\\temp.xml", i) == SAPbobsCOM.BoObjectTypes.oInvoices) {

oJE = oCompany.GetBusinessObjectFromXML("C:\\temp.xml", i);

}

}

MessageBox.Show("LEIDO");

int I = oJE.Add();

if (oJE.Add() == 0) {

MessageBox.Show("OK..!!");

}

READING THE XML BUT AT THE TIME OF EXECUTING oJE.Add(), I DO NOT ADD THE INVOICE TO SAP BO, I FLOW IT AS RESULT THE VARIABLE i = 1;

WHAT ERROR CAN I HAVE?

DOES IT HAVE TO DO WITH THE XML?

OR THE CODE?

WHAT STRUCTURE SHOULD I TAKE XML?

PLEASE HELP ='(

THIS IS MY EMAIL jesus.cortez.1991@gmail.com

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
DIEGO LOTHER Jun 23, 2017 at 07:32 PM
1

Hi Jesus,

Some points:

1. What is the content of you xml? Could you share?

2. There is a mistake in your code that Journal Entry is different from Invoice, the your validation is not correct.

if (oCompany.GetXMLobjectType("C:\\temp.xml", i) == SAPbobsCOM.BoObjectTypes.oInvoices) {
    oJE = oCompany.GetBusinessObjectFromXML("C:\\temp.xml", i);
}

3. If you have a different value from 0 on your oJE.Add() action, you can try get the error message with the following code:

oCompany.GetLastErrorDescription();

4. You shouldn't call twice the method add. After the first time, SDK will clean your object.

int I = oJE.Add();
if (I == 0) {
    MessageBox.Show("OK..!!");
}

Hope it helps.

Kind Regards,

Diego Lother

Show 6 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hello DIEGO LOTHER first thank you for actually commenting I need a lot of help with this code to add an invoice for XML.

Okay, I'll correct those mistakes.

This would be the XML that I try to import (I do not know if the structure is fine) I really need help.

temp.png (37.0 kB)
0

Hi Jesus,

This code should helps you:

int count = oCompany.GetXMLelementCount(@"C:\temp.xml");
SAPbobsCOM.Documents oInv = null;

for (int i = 0; i < count; i++)
{
    if (oCompany.GetXMLobjectType("C:\\temp.xml", i) == SAPbobsCOM.BoObjectTypes.oInvoices)
    {
        oInv = oCompany.GetBusinessObjectFromXML("C:\\temp.xml", i);
        if (oInv.Add() == 0)
            MessageBox.Show("OK..!!");
        else
            MessageBox.Show(oCompany.GetLastErrorDescription());
    }
}

Hope it helps.

Kind Regards,

Diego Lother

1
Former Member
DIEGO LOTHER

Hi Diego,

You see the structure of my XML,

do you think it's fine?

okay..! I already try this code, Thank you very much for the help .

0

Hi Jesus,

Yes, the xml structure it seems correct.

Kind Regards,

Diego Lother

1
Former Member
DIEGO LOTHER

DIEGO, ready already I ran it was problems with xml data, thanks you really were a lot of help.

0

HI Jesus,

Great. Don't forget to click on accept button below my answer if my answer solved your problem.

Kind Regards,

Diego Lother

1