温馨提示:本文翻译自stackoverflow.com,查看原文请点击:axapta - X++ assign Enum Value to a table column
axapta dynamics-ax-2012 x++ dynamics-ax-2012-r3

axapta - X ++将枚举值分配给表列

发布于 2020-05-10 09:48:15

我正在尝试从中拉出Enum所选内容dialog并将其分配label给表的列。

例如:Dialog打开并允许您选择:

表面

超出规格

其他

它们分别是0,1,2。

用户选择OutOfSpec(此标签为Out Of Spec),我想将此枚举的名称或标签放入表中。我要插入的列设置为str

这是我尝试过的代码,没有成功:

    SysDictEnum dictEnum = new SysDictEnum(enumNum(SDILF_ScrapReasons));

    reason = dialog.addField(enumStr(SDILF_ScrapReasons),"Scrap Reason");
    dialog.run();
    if (!dialog.closedOk())
    {
        info(reason.value());
        return;
    }

    ttsBegin;
    // For now, this will strip off the order ID from the summary fields.
    // No longer removing the Order ID
    batchAttr = PdsBatchAttributes::find(itemId, invDim.inventBatchId, "OrderId");
    orders = SDILF_BreakdownOrders::find(batchAttr.PdsBatchAttribValue, true);
    if (orders)
    {
        orders.BoxProduced -= 1;
        orders.update();
    }
    // Adding a batch attribute that will include the reason for scrapping
    select forUpdate batchAttr;    
    batchAttr.PdsBatchAttribId = "ScrapReason";
    //batchAttr.PdsBatchAttribValue = any2str(dictEnum.index2Value(reason.value()));
    batchAttr.PdsBatchAttribValue = enum2str(reason.value());
    batchAttr.InventBatchId = invDim.inventBatchId;
    batchAttr.ItemId = itemId;
    batchAttr.insert();

显然,这不是全部代码,但足以给出我要解决的问题。

我确定有一种获取int值并使用它来分配标签的方法,但我还无法弄清楚。

编辑

添加有关我要完成的任务的更多信息。我们制造我们的成品,有时它们不合规格或损坏,这时我们必须将制成品报废。在执行此操作时,我们希望跟踪其被废弃的原因,但我们并不想仅凭一堆随机原因。我用来enum限制原因。当操作员单击该按钮来刮取某些东西时,他们会弹出一个对话框,允许他们选择进行刮除的原因。然后,代码最终会将分配的原因放在成品批次属性中,以便我们以后可以在报告中进行跟踪,并列出所有报废的成品以及报废原因。

查看更多

提问者
Mike
被浏览
28
Alex Kwitny 2020-02-21 03:07

我不能完全确定您的问题,但我认为您只是错过了一个index2[...]电话,或者您没有从对话框中正确获取返回值。只需将以下内容创建为新作业,运行它,进行选择,Open Order然后单击确定。

我不知道之间的区别index2Labelindex2Name

static void Job67(Args _args)
{
    Dialog          dialog      = new dialog();
    SysDictEnum     dictEnum    = new SysDictEnum(enumNum(SalesStatus));
    DialogField     reason;
    SalesStatus     salesStatusUserSelection;
    str             label, name, symbol;
    int             value;

    reason = dialog.addField(enumStr(SalesStatus), "SalesStatus");
    dialog.run();

    if (dialog.closedOk())
    {
        salesStatusUserSelection = reason.value();

        // Label
        label = dictEnum.index2Label(salesStatusUserSelection);

        // Name
        name = dictEnum.index2Name(salesStatusUserSelection);

        // Symbol
        symbol = dictEnum.index2Symbol(salesStatusUserSelection);

        // Value
        value = dictEnum.index2Value(salesStatusUserSelection);

        info(strFmt("Label: %1; Name: %2; Symbol: %3; Value: %4", label, name, symbol, value));
    }
}