Automatic Number Sequence Attach Code


I find this very great in case if any one wants to attach a number sequence manually created to a particular column in Axapta. We have to write the code in create, write, delete override methods in the table we wanted to have a number sequence to be attached. Here the table is name is Test_Table and the column name for which number sequence to be attached is Test_Num
public void create(boolean _append = false)
{
super(_append);
numberSeq = NumberSeq::newGetNumFromCode("Test_001", true,true);
if (numberSeq)
{
Test_Table.Test_Num = numberSeq.num();
numAllocated = Test_Table.Test_Num;
}
}

public void write()
{
;
ttsbegin;
if (numberSeq && Test_Table.Test_Num == numAllocated)
numberSeq.used();
else
{
if (numberSeq)
numberSeq.abort();
}
super();
ttscommit;
}

public void delete()
{
ttsbegin;
if (!Test_Table.RecId && numberSeq)
numberSeq.abort();
super();
ttscommit;
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.