Tuesday, April 27, 2010

Obtaining the Next Number Sequence via X++

Recently, I needed write a method that would create a line in a custom table for each customer residing in a temporary table (which was actually part of the final process that I briefly mentioned in my last post “Programmatically Inserting Data into a Grid”)

My actual custom Table contained a field that was based on a Number Sequence. Thus in my process, when I programmatically inserted a new record into my custom Table, per customer, I needed to generate the next number sequence for each record. A little digging led me here which revealed some of the code that I was looking for.

On the clicked() method of my “Process” button I essentially did the following:

void clicked()
tbl_Complaint complaintReport;

NumberSequenceReference nsr;
NumberSeq ns;

while select temp

complaintReport.CustNumber = tmt.CustNumber;
complaintReport.Name = tmt.Name;

nsr = tbl_Complaint::numRefComplaintId();
ns = NumberSeq::newGetNum(nsr, false, true);

complaintReport.ComplaintReportId = ns.num();




It should be noted, that in my initial run of the code, I did not include the ttsbegin and ttscommit lines. This however threw the following error:

“System does not support setup 'continuous' of number sequence”
Once again, after doing a little digging, it was here that I learned of my options to resolve this error, which for my needs was solved by implementing transaction scope.

1 comment:

  1. :) I to faced the error : “System does not support setup 'continuous' of number sequence” and wrote the following code to solve the error. thank you for your help

    select VoucherSeqId from projJournalName
    where ProjParameters.PSALogSheetEntryJournalNameId == projJournalName.JournalNameId;
    numberseq = NumberSeq::newGetVoucherFromCode(projJournalName.VoucherSeqId).voucher();// ProjJournalName Table's VocheSeqId
    ProjJournalTrans.Voucher = numberseq;//strfmt("%1",numberseq);//numberseq.voucher();