cancel
Showing results for 
Search instead for 
Did you mean: 

GetNewObjectKey() returning empty

leandro_daminelli2
Participant
0 Kudos

Hello.

I'm adding some documents via DI API. Actually it's 3 documents and i'm adding them using transaction control.

I need the DocEntry of the second document but after Document.Add(), the method Company.GetNewObjectKey() returns empty.

When I commit the transaction, it succesfully create the documents.

What am I doing wrong?

Code sample:


if (lDocumento.Add() != 0)

                    {

                        return false;

                    }

DataSource.SetValue(DataSourceUIDs.CodigoPedidoVenda, 0, mAddOn.Connection.Database.GetNewObjectKey()); //<= Returns empty

Accepted Solutions (1)

Accepted Solutions (1)

maik_delly
Active Contributor
0 Kudos

Hi Leandro,

I cant reproduce your issue in SBO 9.0 PL 11 .Which version are you using ?

The code I used :


SBO_Company.StartTransaction();

for (int i = 1; i < 4; i++)

{

    SAPbobsCOM.Documents oDoc = SBO_Company.GetBusinessObject(BoObjectTypes.oQuotations);

    oDoc.CardCode = "C50000";

    oDoc.DocDueDate = DateTime.Today;

    oDoc.Lines.ItemCode = "A00004";

    oDoc.Lines.Quantity = i;

    if (oDoc.Add() == 0)

    {

        SBO_Application.MessageBox("Run no. "+i+" - NewObjectKey: " + SBO_Company.GetNewObjectKey()); // correct new object keys

    }

    else

    {

        SBO_Application.MessageBox("Error in run no. "+i+": " + SBO_Company.GetLastErrorDescription());

    }

}

if (SBO_Company.InTransaction)

    SBO_Company.EndTransaction(BoWfTransOpt.wf_Commit);

SBO_Application.MessageBox("After commit : " + SBO_Company.GetNewObjectKey());

Can it be that your second dcoument can't be added, instead of return false; print GetLastErrorDescription().

regards,

Maik

leandro_daminelli2
Participant
0 Kudos

Maik, thank you for your attention.

My code is pratically the same of you, and when i commit the transaction all documents are succesfully added. And I don't know if it makes any difference but the document type i'm having problem is "BoObjectTypes.oOrders".

I'm using SAP 9 PL10 64bits, could you please test in the same environment?

maik_delly
Active Contributor
0 Kudos

Hi Leandro,

I get the same results. All 3 new DocEntries are shown - I also tried it with orders.

Have you checked the return values of Add() + GetLastErrorDescription().

Can you post some more of your code ?

regards,

Maik

Edit : Just to make sure I used  SBO 9.0 PL 10 64bit

leandro_daminelli2
Participant
0 Kudos

Maik, I have found an error in my code.. it was my mistake.

I'm using two DI API connections, and unfortunatelly I used the wrong instance to call GetNewObjectKey().

Maybe I need more coffee!

Thank you for your support!

Answers (0)