如何找到AX2009中最后一个labelId?

发布于 2024-12-29 02:28:01 字数 1238 浏览 4 评论 0原文

我想将 labelModuleId 中的所有标签插入 AX2009 表中。

我有这份工作,它几乎可以完成我需要的一切。但我必须输入最大 Id (toLabel = 1000):

static void OcShowAllLabel(Args _args)
{
    xInfo               xinfo;
    LanguageId          currentLanguageId;
    LabelModuleId       labelModuleId = 'OCM'; // hier evt eine Eingabe durch Benutzer zur Auswahl
    LabelIdNum          frLabel;
    LabelIdNum          toLabel = 1000;
    LabelId             labelId;
    OcShowAllLabels_RS  tab;
    Label               blub = new Label();
    str                 label;
    ;

    xInfo = new xInfo();
    currentLanguageId = xInfo.language();
    delete_from tab
        where tab.LanguageId == currentLanguageId
        && tab.LabelModuleId == labelModuleId;

    for (frLabel = 1; frLabel <= toLabel; frLabel++)
    {
        labelId = strfmt('@%1%2', labelModuleId, frLabel);
        label = SysLabel::labelId2String(labelId, currentLanguageId);
        if (labelId != label)
        {
            tab.initValue();
            tab.LabelId = labelId;
            tab.Label = label;
            tab.LanguageId =  currentLanguageId;
            tab.LabelModuleId = labelModuleId;
            tab.insert();
        }
    }

    Info('done');
}

I'd like to insert all Labels from a labelModuleId in an AX2009 table.

I have this job, that does nearly everything I need. But I have to enter the max Id (toLabel = 1000):

static void OcShowAllLabel(Args _args)
{
    xInfo               xinfo;
    LanguageId          currentLanguageId;
    LabelModuleId       labelModuleId = 'OCM'; // hier evt eine Eingabe durch Benutzer zur Auswahl
    LabelIdNum          frLabel;
    LabelIdNum          toLabel = 1000;
    LabelId             labelId;
    OcShowAllLabels_RS  tab;
    Label               blub = new Label();
    str                 label;
    ;

    xInfo = new xInfo();
    currentLanguageId = xInfo.language();
    delete_from tab
        where tab.LanguageId == currentLanguageId
        && tab.LabelModuleId == labelModuleId;

    for (frLabel = 1; frLabel <= toLabel; frLabel++)
    {
        labelId = strfmt('@%1%2', labelModuleId, frLabel);
        label = SysLabel::labelId2String(labelId, currentLanguageId);
        if (labelId != label)
        {
            tab.initValue();
            tab.LabelId = labelId;
            tab.Label = label;
            tab.LanguageId =  currentLanguageId;
            tab.LabelModuleId = labelModuleId;
            tab.insert();
        }
    }

    Info('done');
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尘曦 2025-01-05 02:28:01

如果这是一项一次性工作,您只需停止 AOS 并在记事本中打开标签文件即可。它位于名为 axXXXen-us.ald 的应用程序文件夹中,其中 XXX 是您的标签文件名,en-us 是您的语言。

查看classes\Tutorial_ThreadWork\doTheWork,看看他们在哪里使用 while(sLabel) 而不是像您那样使用 for 循环。

container doTheWork(Thread t,LabelType searchFor)
{
    container   retVal;
    SysLabel    sysLabel = new SysLabel(LanguageTable::defaultLanguage());
    str         slabel;
    ;

    slabel = sysLabel.searchFirst(searchFor);
    while (slabel)
    {
        retVal += sLabel;
        slabel = sysLabel.searchNext();
    }

   return retVal;
}

由于标签文件是一个文本文件,因此您不能只选择最后一个文件,而是必须迭代该文件。然而,AX 会缓存标签,但据我所知,我不相信您可以轻松访问标签缓存。

最后,希望您不会尝试此操作,但不要尝试仅读取标签文本文件,因为 AX 有时具有尚未从缓存刷新到该文件的标签。我认为 Label::Flush(...) 会刷新它们,但我不确定。

If this is a one-time job, you can just stop the AOS and open the label file in notepad. It's in your application folder called axXXXen-us.ald, where XXX is your label file name and en-us is your language.

Look at classes\Tutorial_ThreadWork\doTheWork to see where they use a while(sLabel) instead of a for loop like you have.

container doTheWork(Thread t,LabelType searchFor)
{
    container   retVal;
    SysLabel    sysLabel = new SysLabel(LanguageTable::defaultLanguage());
    str         slabel;
    ;

    slabel = sysLabel.searchFirst(searchFor);
    while (slabel)
    {
        retVal += sLabel;
        slabel = sysLabel.searchNext();
    }

   return retVal;
}

Since the label file is a text file, it would make sense that you can't just select the last one, but you have to iterate through the file. AX caches the labels however, but I don't believe you can just readily access the label cache as far as I know.

Lastly, hopefully you won't try this, but don't try to just read in the label text file, because AX sometimes has labels that it hasn't flushed to that file from the cache. I think Label::Flush(...) will flush them, but I'm not sure.

因为看清所以看轻 2025-01-05 02:28:01

这是我想的另一种选择。您可以插入标签来获取下一个标签编号,然后立即删除它:

static void Job32(Args _args)
{
    SysLabel sysLabel = new SysLabel(LanguageTable::defaultLanguage());
    SysLabelEdit sysLabelEdit = new SysLabeLEdit();
    LabelId labelid;
    ;

    labelId = syslabel.insert('alextest', '', 'OCM');

    info(strfmt("%1", labelId));

    sysLabelEdit.labelDelete(labelId, false);
}

不过,它似乎确实消耗了编号序列中的数字。您可以只执行 Label::Flush(...),然后通过代码检查文本文件。查看 Classes\SysLabel* 以了解系统如何处理标签的一些信息。无论如何,它看起来都不是很简单。

Here is another option I suppose. You can insert a label to get the next label number and then just immediately delete it:

static void Job32(Args _args)
{
    SysLabel sysLabel = new SysLabel(LanguageTable::defaultLanguage());
    SysLabelEdit sysLabelEdit = new SysLabeLEdit();
    LabelId labelid;
    ;

    labelId = syslabel.insert('alextest', '', 'OCM');

    info(strfmt("%1", labelId));

    sysLabelEdit.labelDelete(labelId, false);
}

It does seem to consume the number from the number sequence though. You could just do a Label::Flush(...) and then check the text file via code. Look at Classes\SysLabel* to see some of how the system deals with labels. It doesn't look very simple by any means.

℡寂寞咖啡 2025-01-05 02:28:01

这是另一个可能适合您的选项。这也将识别丢失的标签。将“en-us”更改为您的语言。我认为这是一个“肮脏”的选择。您可能需要添加一些内容来表示“如果我们在一行中找到 5 个类似‘@OCM’的标签”。

for (i=1; i<999; i++)
{
    labelId = strfmt("@%1%2", 'OCM', i);
    s = SysLabel::labelId2String(labelId, 'en-us');

    if (s like '@OCM*')
    {
        info (strfmt("%1: Last is %2", i, s));
        break;
    }
    info(strfmt("%1: %2", i, s));
}

Here is another option that might work for you. This will identify missing labels too. Change 'en-us' to your language. This is a "dirty" alternative I suppose. You might need to add something to say "if we find 5 labels in a row where they're like '@OCM'".

for (i=1; i<999; i++)
{
    labelId = strfmt("@%1%2", 'OCM', i);
    s = SysLabel::labelId2String(labelId, 'en-us');

    if (s like '@OCM*')
    {
        info (strfmt("%1: Last is %2", i, s));
        break;
    }
    info(strfmt("%1: %2", i, s));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文