Auto Numbering new PO’s using Catalina’s API for Dynamics SL

Many times, we want to be able to create Purchase Orders, using the Catalina API for Dynamics SL, and don’t want to worry about having to create the PO Number ourselves so that we don’t reuse a PO number, etc.  This is a function of Dynamics SL and is configured in the POSetup table.  If you look at the POSetup table, at the AutoRef column, it can be either a 0 or a 1:

autopocheck

If it is a 1, it means that SL will auto-number for you and if you leave the PoNbr blank when you call the ctDynamicsSL.purchaseOrders.saveNewPurchaseOrder function it will auto generate it for you, just like sales orders.

If PO Auto numbering is not enabled, POSetup.AutoRef=0  then you have to specify the PONbr yourself.  But dont worry, we have a work-around for this that will generate a custom incremented number for you by calling this Catalina API call:

[code lang=”csharp”]
ctDynamicsSL.common.getNextCounterAsString(counterName);
[/code]

This function uses the xct_tblDSLCounter table to determine the next number value.  This table is a Catalina table that is used for anything you want to have a counter for and is keyed off of the column: counterName.  If you create a new record with the counterName = “PONBR”, you can then do an API call like this to get the next number:

[code lang=”csharp”]
string nextPONbr = ctDynamicsSL.common.getNextCounterAsString("PONBR");
[/code]

Looking further in the xct_tblDSLCounter table, you can see the following fields:

  • counterName: This is the key to determine which counter you want to increment
  • counterPrefix: If you want to have some type of custom prefix on your counter, you can enter something here
  • counterAmt: this is the last counter used
  • minWidth: this will make sure that you have a certain width of number come out (not including the prefix)

Lets create a record in the table for PONBR.  I just choose PONBR because it makes sense to me.  But you could use any counterName.  Or for that matter, you could have several records for PO Numbers so that you can have separate prefixed counters for different applications that might be feeding your PO’s.

[code lang=”sql”]insert into xct_tblDSLCounter
values(‘PONBR’, ‘PO’, 0, 5)
[/code]

So, if I make this call:

[code lang=”csharp”]
string nextPONbr = ctDynamicsSL.common.getNextCounterAsString("PONBR");
[/code]

The first time I call it, it will give me a value for nextPONbr

PO00001

The second time I call it, it will give me a value for nextPONbr

PO00002

The one hundredth time I call it, it will give me a value for nextPONbr

PO00100

Catalina Integrator – Catalina’s API Mapping Tool
Dynamics SL Quick Query through Catalina’s RESTful API