Next In Sequence II

Hi all, From an earlier discussion (‘Next In Sequence’, I am working on creating Gen. Journal Lines to post to G/L (instead of creating G/L Entries directly). My original question was how to find ‘last in sequence’ in a table, so that I could add add’l rows. The reponse from LarsW (thanks again!) was: IF GLEntry.FIND(’+’) THEN NextNo := GLEnry.“Entry No.” + 1 ELSE NextNo := 1; // note this was for G/L Entry; now Gen. Journal LInes I’m trying to apply this same logic for Gen. Journal Lines, but am having a problem. The FIND results in a Line No. that is somewhere in the middle of the table, not the last I expected. I’ve tried setting the Journal Template and Journal Batch values to be the same as the one I’m using and setting SETCURRENTKEY to the proper key. But it still returns this mid-table value. I had been ignoring this as an anomaly. But there is another (related?) problem. I can run the process once and successfully create a set of journal lines. But when I try to do a repeat run, the FIND continues to find the same Line No. (mid-table value) as the 1st time it was run. It ignores (doesn’t FIND) the Line No.'s for all the new entries created earlier. Thus fails on INSERT on the second-round records. What’s my problem?

Your problem is probably that before you do this FIND(’+’), you set filters on the table. The FIND then proceeds and actually does find the last record within the filter, although this may not actually be the last record in the table. Try locking the table, doing a FIND(’+’) before you set your filters (so you have your last number used) and go from there.

No, I think the problem is that he is not setting filters at all. larry, try something like this: with gejnlline do begin reset; setrange("gen jnl template name",MyTemplate); setrange("gen jnl batch name",Mybatch); if find('+') then nextjnllineno := "line no" + 10000 else nextjnllineno := 10000; end;

I guess I should have been a little more clear. I think the problem is that he is getting the last number using one filter and the writes new lines using a different filter. I think he gets the last number in MyTemplate and MyBatch, and then uses that value to enter new transactions in YourTemplate and YourBatch. So next time this function is run, it will get the error that Larry describes. I think this problem can be solved by investigating the filters that are used to get the last number and the values that are being set in new transactions.

Thanks all. I followed David’s model, and the suggestions of others. Worked perfectly. Appreciate the help!

you’re welcome