Getting new PurchId via .NET BusinessConnector

601 views Asked by At

I am trying to find a .NET BusinessConnector equivalent call for the below line:

PurchId = NumberSeq::newGetNum(SalesParameters::numRefSalesId()).num();

I am manually entering purchase order information into the purchase order table, which is fine, but the problem lies in the fact that it is the PurchID that ties purchase table (PURCHTABLE) and the individual purchase order lines (PURCHLINE) is the PURCHID field, which is not automatically populated when saving a purchase order.

Currently I am:

   ax.TTSBegin();
   axRecord.set_Field("ORDERACCOUNT", purchaseOrder.OrderAccount);

(etc)

   axRecord.Insert();

However, while this will insert a record into the database, it has no purchID, which has to be generated. You need a purchID to link the purchase line items in. I found the above code (second line) for X++, but does anyone know of a .NET BusinessConnector call that can be used instead?

Any assistance would be greatly appreciated.

Regards, Steve

2

There are 2 answers

5
Jan B. Kjeldsen On BEST ANSWER

I would go for a change in the insert() method of the PurchTable table:

if (!purchTable.PurchId)
    purchTable.PurchId = NumberSeq::newGetNum(purchParameters::numRefPurchId()).num();

Placed after the ttsbegin.

This to avoid complicated C# code. You probably could do it in C# code alone using CallStaticClassMethod and cousins, but it is better do put the buisness logic on the X++ side.

See How to: Call Business Logic Using .NET Business Connector.

0
Markus Palme On

Be sure to execute inside a TTSBegin/ TTSCommitblock, otherwise you will get error error messages like this one.

// ax is a reference to an "Axapta" business connector object
var numRef = ax.CallStaticRecordMethod("SalesParameters", "numRefSalesId");
var numSeq = (AxaptaObject)ax.CallStaticClassMethod("NumberSeq", "newGetNum", numRef);
var purchId = numSeq.Call("num");