09 October 2009

Create a new Numbersequence for an existing Module

Although there are some good post about this online I post another short instruction bout "How to create a NumberSequence" here:
  1. create an EDT - in this Example we call it MyNewNumberSeqId
  2. Edit the loadModule Method of the NumberSeqReference_... Class of your Module add this code
    numRef.DataTypeId              = typeId2ExtendedTypeId(typeid(MyNewNumberSeqId));
    numRef.configurationKeyId      = configurationkeynum(ABCBasic);
    numRef.ReferenceHelp           = literalstr("@ABC123");
    numRef.WizardContinuous        = true;
    numRef.WizardManual            = NoYes::No;
    numRef.WizardAllowChangeDown   = NoYes::No;
    numRef.WizardAllowChangeUp     = NoYes::No;
    numRef.SortField               = 1;
    this.create(numRef);
  3. create a new method in the ParametersTable of the Module - For Example SalesParameters
    public client server static NumberSequenceReference numRefMyNewNumberSeqId()
    {
        ;
    
        return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(MyNewNumberSeqId)));
    }
  4. done
to use this NumberSequence create a numberSeq object and call its num method. I often call this method in the insert of the Datasource in which the NumberSequence is used:
public void insert()
{
    NumberSeq  numberSeq;
    ;
    if (this.MyNewNumberSeqId== "")
    {
        numberSeq = NumberSeq::newGetNum(SalesParameters::numRefMyNewNumberSeqId());
        this.MyNewNumberSeqId= numberSeq.num();
    }
    super();
}

No comments: