Skip to Content
0

DI API Add Cannot Work

Feb 26 at 07:55 AM

78

avatar image

Hi,
I was trying to add new Item into Purchase Request by using DI API. Didn't occure any error when I run code but it didn't add into table. I checked OPRQ and also PRQ1 tables, both them are empty. Could you tell me where is the wrong? Here is my code:

 SAPbobsCOM.Documents vItem;
            try
            {
               
                vItem = (SAPbobsCOM.Documents)vCmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseRequest);
                vItem.Comments = "TEST";
                vItem.DocDate = System.DateTime.Now;
                vItem.DocDueDate = System.DateTime.Now.AddDays(1);               
                vItem.Add();
                Application.SBO_Application.MessageBox("ok");
            }
            catch (Exception ex)
            {
                Application.SBO_Application.MessageBox(ex.ToString());
            }

10 |10000 characters needed characters left characters exceeded

You can use this code to print out an error massage and get a good idea of what is wrong:

int res = vItem.Add();
if (res != 0)
{
    int errorCode = 0;
    string errorDesc = "";
    vCmp.GetLastError(out errorCode, out errorDesc);
    
    Application.SBO_Application.MessageBox($"Inserting Item failed ({errorCode}, {errorDesc}).");
}
0

Hi Szabolcs,

Thank you for answer. I tried that you said and I can see now the error mesage. The message: No matching records found (ODBC -2028)

Do you know why this error happenning?

0
Hatice Kose Ziyali

Hi Hatice,

DI API would work the same business logic as the SBO Application.
Can you generate the Purchase Request in SBO Application by the limited information you passed in your Code?
For a start, I don't see you pass any itemCode/accountCode in your code.


Regards
Edy

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
DIEGO LOTHER Mar 02 at 02:37 PM
0

Hi Hatice,

As Edy Simon mentioned on the comments, your code should provide the minimum information to create a purchase request, like we do on the SAP Business One client.

On SDK help center you are able to see samples of how to add documents with SDK.

A small sample:

            try
            {
                SAPbobsCOM.Documents oDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseRequest);
                oDoc.SendNotification = SAPbobsCOM.BoYesNoEnum.tNO;
                oDoc.ReqType = 12; //user or 171 as employee
                oDoc.Requester = "manager";
                oDoc.RequriedDate = DateTime.Now;
                oDoc.Lines.ItemCode = "A00001";
                oDoc.Lines.Quantity = 1;


                //If you want more itens, call oDoc.Lines.Add(); before provide new items code.


                if (oDoc.Add() != 0)
                    MessageBox.Show(oCompany.GetLastErrorDescription());


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Hope it helps.

Best Regards,

Diego Lother

Share
10 |10000 characters needed characters left characters exceeded