1. 程式人生 > >X++:自定義Number sequence&應用

X++:自定義Number sequence&應用

通過本教程你可以很簡單地在Dynamics 365裡面自定義一個Number sequence(派號碼),並能使用它獲取一個新的number.

 

  1. 先確認在哪個版塊中應用此Number sequence, 我們選擇了Production control,  需要在Production control->Setup->Production control parameters的Number sequences裡面加上若干個Number sequence. 那麼Production control的number sequence的設定涉及到兩個class要修改:
    1. NumberSeqModuleProduction
    2. ProdParameters
  2. 基於NumberSeqModuleProduction新建一個擴充套件AEL_NumberSeqModuleProd_Extension:
[ExtensionOf(classStr(NumberSeqModuleProduction))]
final class AEL_NumberSeqModuleProd_Extension
{
    protected void loadModule()
    {
        next loadModule();
        
        this.AEL_AddDataType(extendedtypenum(AEL_ProdRNoteId_IR),  8, literalstr("@AEL580"), literalstr("@AEL579"));
        this.AEL_AddDataType(extendedtypenum(AEL_ProdRNoteId_LR),  9, literalstr("@AEL581"), literalstr("@AEL582"));
        this.AEL_AddDataType(extendedtypenum(AEL_ProdRNoteId_PS), 10, literalstr("@AEL583"), literalstr("@AEL584"));
        this.AEL_AddDataType(extendedtypenum(AEL_ProdRNoteId_IS), 11, literalstr("@AEL585"), literalstr("@AEL586"));
        this.AEL_AddDataType(extendedtypenum(AEL_ProdRNoteId_LO), 12, literalstr("@AEL587"), literalstr("@AEL588"));
        this.AEL_AddDataType(extendedtypenum(AEL_ProdRNoteId_ER), 13, literalstr("@AEL589"), literalstr("@AEL590"));
        this.AEL_AddDataType(extendedtypenum(AEL_ProdRNoteId_RS), 14, literalstr("@AEL591"), literalstr("@AEL592"));
    }

    private void AEL_AddDataType(
        ExtendedTypeId _datatypeId,
        Integer _sortField,
        NumberSequenceRefLabel _referenceLabel = '',
        NumberSequenceRefHelp _referenceHelp = ''
    )
    {
        NumberSeqDatatype datatype = NumberSeqDatatype::construct();
        datatype.parmDataTypeId(_datatypeId);
        if (_referenceLabel)
        {
            datatype.parmReferenceLabel(_referenceLabel);
        }
        if (_referenceHelp)
        {
            datatype.parmReferenceHelp(_referenceHelp);
        }
        datatype.parmWizardIsContinuous(false);
        datatype.parmWizardIsManual(NoYes::No);
        datatype.parmWizardfetchAheadQty(10);
        datatype.parmWizardIsChangeDownAllowed(NoYes::No);
        datatype.parmWizardIsChangeUpAllowed(NoYes::No);
        datatype.parmSortField(_sortField);
        datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
        this.create(datatype);
    }

}

AEL_ProdRNoteId_IR…這些是edtString型別

3.基於ProdParameters新建擴充套件AEL_ProdParameters_Extension:

[ExtensionOf(tableStr(ProdParameters))]
final class AEL_ProdParameters_Extension
{
    public static NumberSequenceReference AEL_NumRefRepNoteId()
    {
        return NumberSeqReference::findReference(extendedTypeNum(AEL_ProdRepNoteId));
    }

    public static NumberSequenceReference AEL_NumRefERRepNoteId()
    {
        return NumberSeqReference::findReference(extendedTypeNum(AEL_ProdRNoteId_ER));
    }

    public static NumberSequenceReference AEL_NumRefIRRepNoteId()
    {
        return NumberSeqReference::findReference(extendedTypeNum(AEL_ProdRNoteId_IR));
    }

    public static NumberSequenceReference AEL_NumRefISRepNoteId()
    {
        return NumberSeqReference::findReference(extendedTypeNum(AEL_ProdRNoteId_IS));
    }

    public static NumberSequenceReference AEL_NumRefLORepNoteId()
    {
        return NumberSeqReference::findReference(extendedTypeNum(AEL_ProdRNoteId_LO));
    }

    public static NumberSequenceReference AEL_NumRefLRRepNoteId()
    {
        return NumberSeqReference::findReference(extendedTypeNum(AEL_ProdRNoteId_LR));
    }

    public static NumberSequenceReference AEL_NumRefPSRepNoteId()
    {
        return NumberSeqReference::findReference(extendedTypeNum(AEL_ProdRNoteId_PS));
    }

    public static NumberSequenceReference AEL_NumRefRSRepNoteId()
    {
        return NumberSeqReference::findReference(extendedTypeNum(AEL_ProdRNoteId_RS));
    }

}

4.完畢後,在瀏覽器上執行

  1. https://usnconeboxax1aos.cloud.onebox.dynamics.com/?mi=SysClassRunner&cls=AEL_LoadNumberSequence 重建Number sequences.

5.手動加入Number sequence專案:  進入Organization administration->Number sequences->Number sequences, New Number sequence:

6.再開啟Production control->Setup->Production control parameters的Number sequences引用這個新建的RNOTE_IR:

7.如何應用: 在table新建的時候,從number sequence中取得新的id:

修改AEL_ReplacementNote_master table加上insert method:

this.AEL_rl_no = NumberSeq::newGetNum(ProdParameters::AEL_NumRefIRRepNoteId()).num();