Tuesday 5 June 2018

Import label files X++

Following job can be used to import multiple label files from a folder. The label files are not automatically saved in AOT so a manual Save all is required.

static void LabelFileImport(Args _args)
{
    #File
    
    FilePath                        directoryPath, filePath;
    Filename                        fileName, fileNameWithPath;
    SysLabelFile                    labelFile;
    Set                             languages;    
    
    System.String[]                 files;
    System.Collections.IEnumerator  enumerator;
    
    directoryPath = @"D:\TempNav\LabelFiles"; // folder to import from
    info(strFmt("Import path: %1", directoryPath));
    
    try
    {
        files = System.IO.Directory::GetFiles(directoryPath, '*.ald');
        enumerator = files.GetEnumerator();
    }
    catch
    {
        info(strFmt("Failed to get file list from path %1", directoryPath));
    }
    
    if (enumerator)
    {
        while (enumerator.MoveNext())
        {
            fileNameWithPath = enumerator.get_Current();
            
            try
            {
                [filePath, fileName] = fileNameSplit(fileNameWithPath);
                
                labelFile = SysLabelFile::newFilename(fileNameWithPath);
                languages = new Set(Types::String);
                languages.add(labelFile.parmLanguageId());
        
                SysLabelFile::createLabelFileInAOT(labelFile.parmModuleId(), languages);
                labelFile.importAldFile(fileNameWithPath);
        
                info(strFmt("@SYS322092", fileName));
            }
            catch
            {
                info(strFmt("Filed to import file %1", fileName));
            }
        }
    }
}

This posting is provided "AS IS" with no warranties. Use code at your own risk.