cancel
Showing results for 
Search instead for 
Did you mean: 

GetNewObjectCode Method of Company Object

rajesh_khater
Active Participant
0 Kudos

Hi,

As per the SDK Reference, the GetNewObjectCode method of the Company Object retrieves the key of the last added record.

"

You can use this method, for example, to create a payment based on an invoice:

  1. Create invoice.
  2. Get the key for identifying the invoice (Invoices property of the Payments object).
  3. Create the payment.

"

Suppose between Step 1 and Step 2, another user creates an Invoice, or even same user creates an Invoice manually using the SBO application . What values will the GetNewObjectCode method return? Is it guaranteed to return the key of the last object created by the current user in the current session?

If not, what is the other way?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Rajesh,

B1 doesn't know which user creates the last of any objects. So, if in the process you are implementing, you cannot get and keep the LastCode just after having added the object, then you need to have a different way to query for the specific invoice before dealing with the payment.

Regards

Eric

rajesh_khater
Active Participant
0 Kudos

Hi Eric,

It is not specific to my process. In general, in a concurrent multi user environment, these kinds of things can happen.

What that different way can be? Like I store a unique UDF (may be a GUID value generated from .NET) in the Invoice document, and then query for that Invoice document which has that unique UDF value ?

Or any simpler approach which I am missing?

Thanks.

Former Member
0 Kudos

Hi Rajesh,

I agree about the environment. But if get the new object code, just after having posted the invoice, then you are 99.99% garanteed to have the correct one.

What I'm doing (had the issue seveval time, is to document.Add() the invoice and if 0 then get the object code, then generate the payment (which is one the tests for which I provided samples).

But if you have a time lag between the generation of the invoice, then the payment, then for sure you need an extra method to precisely determine the document to pay.

Regards,

Eric

rajesh_khater
Active Participant
0 Kudos

You are right Eric in saying 99.99%.

But I want to be 100% sure.

Even if I get the object code immediately after posting the invoice, there is a 0.0001% chance that someone else might have created an invoice in the mean time, and I may not get the correct code! And once a wrong payment is posted, correcting it can be a big pain.

I guess if I am programmatically creating the invoice, I can read the invoice again from the database using the object code and verify whether it matches with the data used to create the invoice!

Or else a GUID approach may do.

Anyway, since this is a rare scenario, I think I will not spend too much time on this issue.

Former Member
0 Kudos

Hi Rajesh,

B1 is using transactions... And is know to be "strange" on that one. So conceptually this is 99.99%, but because of internal issues you will never encounter the problem.

But by the way, I have not tested this: meaning if the GetNewObjectCode is global to B1 or specific to a DI commection.

If this is the second, you are on 100%.

I have no time to test this today... Perhaps next week...

Regards,

Eric

Answers (0)