Number series error in NAV 2013

Hi all…

I’m having trouble with a number series created by me.

I have created a number series and attached it to the “External Document No.” of “Gen. Journal Line” table or to the Payment Journal page.

The series is working fine, the problem is if I delete a line from Payment Journal without posting the line,

then insert a new line the number series is not resetting.

Eg. I’m deleting the line with Ext. Doc. No. - 1002,

and insert a new line,

the Ext. Doc. should be 1002, But it is not giving it. It gives number 1003.

Can anyone tell me how to correct this.

Hi Sriyantha,

There is no standard automation around the External Document No. because this is an external number normally provided by your external customer/vendor.

But you want to create the functionality you describe above, then you should create the code on the “onDelete” trigger in the table. Here you need to create new code to update the numbers on the remaining lines.

Thanks Erik,

Yes I want to write the code in OnDelete trigger.

But I don’t want to update the remaining records.

I want to update the Last No. field of No. Series table with the deleted record’s Ext. No

But I don’t know how to do it.

What if you have created 2 lines with 1002 and 1003

and you are deleting 1002.

How should it work?

@ Mohana,

The new line should have No. 1004.

I think in the base product also the same thing happens.

Why do you want to reset no. series in your example…

It is working fine as per base product only…did you check that?

Do you mean to say when you delete the line due to some reason the no series should reset again ???

@ mohana & @Amol

What I realu want is, not to reset no seres.

I want to update the “Last No. Used” field of “No. Series” table with the last No that is in “Payment Journal” page.

When I delete a record in “Payment Journal” page, same time I want to select the remaining last line No.

I cant do that.

Does anyone know how to get the last remaining record after deleting the last record

Eg. If I have record 1001,1002,1003,1004 and I’m deleting record 1004, and I want get 1003 to a variable at the same time.

Here I would like ask you why you want to do that ?

You can get it from last no used field of no series

When I’m deleting a record “Last No. Used” is not updating (not decrementing).

It updates only when Inserting a new record(incrementing only) .

So to to decrementing it manually I want the last record number which is in “Payment Journal” Page.

Hi Sriyantha,

So I really have two separate trains of thought going here. In the first, I’ll beg the question and, in the second, I’ll attempt to answer it.

First, let’s ask WHY you want to do this (other than the obvious possibility that it simply offends your sense of order.) What’s the point? You’ve already said that, in the case where you delete a line that has an Ext Doc No value of anything other than the Last No Used, you don’t want to do anything; and that you only want to act if the Ext Doc No value matches the Last No Used. If I’ve understood you correctly, then you must not be concerned about gaps. And if you’re not concerned about gaps then why do you need to treat the two deletion events differently? The only thing that comes to mind to possibly answer that question would be that you’re worried about running out of numbers. If that’s the case, then it would be far easier to change the series definition to include a few more digits. You have lots of space available to do that. If, on the other hand, you really are doing this because it offends your sense of order, then maybe you might consider an alternate venue for addressing this kind of hitch in your mental get-along? If you don’t have a solid business case for dealing with this, then leave it alone. If you do have a valid business case, maybe you could let us in on it?

On the second train of thought - suggesting actual answers to your question - I can think of a couple of options. To begin with, you might try not assigning values to the Ext Doc No field until you post the journal. If that doesn’t cause issues elsewhere, it would certainly solve the problem. Or, you can build a function that returns the highest value of Ext Doc No within the current journal batch, and then call that function in the OnDelete trigger of the form or page. For the function design, you would pass the rec variable to the function, and return a Code10 which would represent the value you’re looking for. The process in the function would either make use of SETCURRENTKEY and FINDLAST, or wheel through the recordset using REPEAT…UNTIL and testing to see whether the Ext Doc No value in the current record is the highest and, if it is, updating your function return variable accordingly. The choice of which approach to use would depend on your aversion/attraction to the idea of declaring a local copy of the t_81 object and creating a key for that table that appropriately includes the Ext Doc No field and, alternatively, your feelings about wheeling through the entire journal just to find a single value. Or, you could create an entirely different function, in which you inspect the value of the Ext Doc No field in the line being deleted, compare it to the value of Last No Used in your No Series, and decrement the Last No Used value if they match. I’m sure there are many other options too, if you must.

Hope that helps.

Do you mean to say when you delete the record then it should update the record in no series ???

If yes then you need to customize the same .

OK as I think you all have misunderstand the question.

This is the sample

In my Payment Journal page I have these lines

"No." “Document No” “External Document No.” "Amount"

1 Doc001 Ext001 200.00

2 Doc002 Ext002 300.00

3 Doc003 Ext003 400.00

4 Doc004 Ext004 500.00

In my No. Series form as the “Last Used No.” of “External Document No.” having ‘Ext004’

Then I’m deleting the last two lines (“No.” 4 & 3).

Then I check the “no. Series” form still the “last Used No.” is ‘Ext004’

I want to make it “Ext002”, because it is the last number I’m having in my payment journal.

After I deleted the lase two lines(“No.” 4 & 3).

Hi Sriyantha,

I think that you and I have said the same thing. You want to roll back the value of the Last No Used field in the No Series record under certain circumstances.

The methods I offered for doing this are still valid (although the scenario where you’re deleting multiple lines simultaneously would probably require some additional coding if you opted for a method other than not populating the Ext Doc No until you post), as is the challenge to your reason for wanting to do it in the first place.

Hi Roshan,

As I asked before, what if you delete the first 2 lines? Ext001 and Ext002?

Why do you want to do it only while deleting last records and not first records?

Dont you want to create next created document with Ext001?

Hi George,

I tried it before, but the problem is in the OnDelete function,

if we create a rec variable of the same table(t_81) and loop through it to the last record,

it gives me the record I’m deleting. So I can only get the record that I’m deleting. not the one before.

And if I used ‘Rec’ OR ‘xRec’ to get the remaining last record it gives the record that I,m deleting now.

I think there will be lot of scenarios before doing this and lot of implications .Just think before doing the changes…

Hi George,

Thanks for the replay.

I tried your solution. I wrote a method to get the last Ext. No from the current journal batch, and call it inside the Ondelete method as you said. But still it returns the External Document No. that I’m deleting (If I’m deleting the last line of the journal batch).

What I want is to get the Ext. No of the line remaining after deletion.

And I want to do it OnDelete function.

Thanks.

Can you show us the code?