cancel
Showing results for 
Search instead for 
Did you mean: 

How to get DocEntry from UI?

0 Kudos

Hi,

How to get DocEntry from UI? I have used below code to get DocEntry -

oCompany.GetNewObjectType();

oCompany.GetNewObjectKey();

Application.SBO_Application.MessageBox(oCompany.GetNewObjectKey());

But it is giving error as "Object reference not set to an instance of an object.". Is there any other way to get DocEntry? Please help me.

Regards,

Neha

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Dear s_neha,

GetNewObjectKey() method retrieves the key of the last added record.

While the error message "Object reference not set to an instance of an object" clearly states that there is something which hasn't been instantiated properly.

Make sure that your company connection is successful and everything is properly instantiated.

Here is a sample which will give you the last added Sales Order Number:

SAPbobsCOM.Documents oSalesOrder = (SAPbobsCOM.Documents)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
oSalesOrder.CardCode = "C20000";
oSalesOrder.DocDueDate = DateTime.Now;
oSalesOrder.Lines.ItemCode = "A00001";
int A = oSalesOrder.Add();
if (A == 0)
{
    var dockey = company.GetNewObjectKey();
    var docType = company.GetNewObjectType();
}

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

Hi,

Yes, Resolved.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

Hi,

It was glad to know that the issue has been resolved for you.

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

0 Kudos

Hi,

Yes, My company connection is successful and I'm getting doc Entry by using below code:

int offset = oForm.DataSources.DBDataSources.Item(0).Offset; string DocEntry = oForm.DataSources.DBDataSources.Item(0).GetValue("DocEntry", offset);

Thanks for the help.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Dear s_neha,

What is the current status now? Is your issue resolved?

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

0 Kudos

Hi Ankit,

This is my code:

oCompany = (SAPbobsCOM.Company)oApp.Company.GetDICompany();

SAPbobsCOM.Documents oSalesOrder = (SAPbobsCOM.Documents)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders); oSalesOrder.CardCode = "C20000";

oSalesOrder.DocDueDate = DateTime.Now;

oSalesOrder.Lines.ItemCode = "A00001";

int A = oSalesOrder.Add();

if (A == 0) {

var dockey = oCompany.GetNewObjectKey();

var docType = oCompany.GetNewObjectType();

Application.SBO_Application.MessageBox(dockey); }

Is there anything wrong? Cz I getting same error..And I want to know that , How can we get DocEntry of current open record?

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Dear s_neha,

  1. Is your company connection successful?
  2. Is the Sales Order being added successfully using your code?
  3. At which line, do you get this error?

Kind regards,

ANKIT CHAUHAN

SAP Business One Support