cancel
Showing results for 
Search instead for 
Did you mean: 

DI API Add Cannot Work

hziyali
Explorer
0 Kudos

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());
            }

former_member231954
Participant
0 Kudos

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}).");
}
hziyali
Explorer
0 Kudos

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?

edy_simon
Active Contributor
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member185682
Active Contributor
0 Kudos

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

Answers (0)