Skip to Content

GetNewObjectKey() returning empty

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
Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Jun 05, 2014 at 06:12 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.