Posting Routine problem

Hello good people. i have ans issue here.

i have created two custom tables. A journal line table and and an entry table with corresponding forms.

i use journal line form to make entries which i want to post to the entry table when i press a button with code on the onpush trigger.

The erro i get is “Drug Update journal cannot close because the system is currently working”. when i say ok the error that pops says "Drug Register Entry Entry No’0’ already exists. Entry No. is primary key in entry table. below is my code.




DrugEntry.“Journal Batch name” :=RegLine.“Journal Batch name”;

DrugEntry.“Reg No.”:=RegLine.“Reg No.”;

DrugEntry.“Drug name”:=RegLine.“Drug name”;

DrugEntry.“Generic Name”:=RegLine.“Generic Name”;

DrugEntry.“Date of Update”:=RegLine.“Date of Update”;

DrugEntry.“Reason/Comment for Update”:=RegLine.“Reason/Comment for Update”;

DrugEntry.LHolder:=RegLine.“LHolder No.”;

DrugEntry.“Pack Size”:=RegLine.“Pack Size”;

DrugEntry.“Updated By”:=USERID;

DrugEntry.“Licence No.”:=RegLine.“Licence No.”;

DrugEntry.“ATC Code”:=RegLine.“ATC Code”;

DrugEntry.“LTR No.”:=RegLine.“LTR No.”;

DrugEntry.LHolder:=RegLine.“LHolder No.”;

DrugEntry.“Shelf Life”:=RegLine.“Shelf Life”;


DrugEntry.“Product Status” := RegLine.“New Status”;


// To flag the register

IF Drug.GET(RegLine.“Reg No.”) THEN BEGIN

Drug.“Reason/Explanation”:=RegLine.“Reason/Comment for Update”;

Drug.“Date of Update”:=RegLine.“Date of Update”;


Drug.“Updated By”:=USERID;

Drug.“Product Status”:=RegLine.“New Status”;





I’ll appreciate your help

Hi Simon,

As far as I can see then never assign any value to the DUGentry.“Entry No.” field. Thus the value is always 0 when you try to insert.

Hi Erik,

As you can see in my code, there no assignment to the Entry No. field. Entry no is primary key in the Drug Entry table

It doesn’t matter that it’s the primary key, you still need to assign the value. And the error is telling you so!

You do have an option to make SQL do it automatically, but if you’re using that, then you still need to assign 0 to the field (or clear entry record before inserting)-

I am lost Erik,

i did an init on the entry table, couldnt help. i have done clear too but still no success

The INIT function does NOT reset the values of the primary fields. If you don’t believe me, then run it with the debugger, then you can see it yourself.

So you need to manually assign value 0 to the field, if you’re using the automatically assignment of entry numbers.

You need to increase the Entry No field whenever the record get inserted .

Define one integer variable and increase the number whenever the record get inserted by checking the last record of table.

Amol, if the AutoIncrerment propery is turned on for the Entry No. (Integer) field is turned on the new entry tabel, then it’s just required to set the Entry No. to 0 - then SQL automatically assigns the next number. But only when it’s being set to 0, not when using INIT.

Hi Erik, the autoincrement property is Yes for Entry.No field. then i do DrugEntry.“Entry No.”:=0; but instead the error now is "Drug Register Entry Entry No.‘1’ Already exists. how abt we do a team viewer session plizzzz. the deadline is due. please

hi Amol,

i have tried doing that but no success. may be a step by step guide would do. pliz.