Site icon DAXRunBase

Team Foundation Server and AX labels

Today we will cover the topic of using labels with the Team Foundation Server (TFS) as our Microsoft Dynamics AX Version Control System (VCS).

If you set up a new environment from scratch and your repository is empty, you can import your existing ALD label files to AX and add it to VCS in 2 easy steps.

1) You may use the standard “ALDImport” startup command with the AX client and pass in your labels one by one, or use the following code to import all files from a specific folder with the help of .Net managed code:

static void WIK_ImportLabelFromFolder(Args _args)
{
    #AOT

    SysLabelFile            labelFile;
    Set                     languages = new Set(Types::String);
    System.Array            fileList = System.IO.Directory::GetFiles(@"C:\TEMP\", "*.ald");
    Filename                fileName;
    int                     i;

    for (i = 0; i < CLRInterop::getAnyTypeForObject(fileList.get_Length()); i++)
    {
        fileName = CLRInterop::getAnyTypeForObject(fileList.GetValue(i));
        info(fileName);
        labelFile = sysLabelFile::newFilename(fileName);
        languages.add(labelFile.parmLanguageId());

        if (!Treenode::findNode(strfmt(#LabelFileLanguagePath,
            labelFile.parmModuleId(),
            strReplace(labelFile.parmLanguageId(), '-', '_'))))
        {
            SysLabelFile::createLabelFileInAOT(labelFile.parmModuleId(), languages);
        }

        labelFile.importAldFile(fileName);
    }
    info("Done");
}

2) Once you have your labels in the AOT, you have to dump all the languages within that label node to the TFS repository, which would be the axWIKEN-US.ALD file in my case:

static void WIK_AddLabelToVCS(Args _args)
{
    #AOT
    #define.LanguageModuleId('WIK')

    TreeNode                node;
    SysLabelFile            labelFile;
    TreeNodeTraverser       tnt = new TreeNodeTraverser(
        TreeNode::findNode(strFmt(#LabelFileLanguagesPath,
        #LanguageModuleId)).AOTfirstChild());
    SysVersionControlSystem vcs = versioncontrol.parmSysVersionControlSystem();

    node = tnt.next();

    while (vcs && node)
    {
        labelFile   = SysLabelFile::newLanguageModule(
            strReplace(node.AOTname(), '_', '-'), #LanguageModuleId);
        vcs.commandAdd(labelFile);

        node = tnt.next();
    }
}

 

Exit mobile version