web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Import, Export Label to Exel

(0) ShareShare
ReportReport
Posted on by

Hi all,

I follow this link : http://www.agermark.com/2011/10/export-and-import-labels-for.html

Palle Agermarks wrote 2 jobs that import and export label to exel, i use with AX 2012 and after fix some errors but some errors i don't know how to fix its.

Please, how i can fix this error ?

Thank you so much !

export_5F00_import_5F00_labels.PNG

And this is the code of two jobs :

"TransformLabelsInExel2XPO"

// This job converts an Excel file, generated with \Jobs\Exportlabels2Excel, to an XPO file.
// With the XPO file you can standard the import tool to import the changed labels.
// Do not import the job from the XPO. It is only there as placeholder for the la bels.
static void TransformLabelsInExcel2XPO(Args _args)
{
    FileName                excelFileName;
    FileName                xpoFileName;

    Dialog                  dialog;
    DialogField             dialogFieldExcelFileName;
    DialogField             dialogFieldXPOFileName;

    SysExcelApplication     application;
    SysExcelWorkBooks       workBooks;
    SysExcelWorkSheets      workSheets;
    SysExcelWorkSheet       workSheet;
    SysExcelCells           cells;
    SysExcelCell            cell;

    Counter                 columnCounter;
    Counter                 rowCounter;
    Counter                 maxColumn;

    Map                     languageIdMap = new Map(extendedTypeNum(Counter), extendedTypeNum(LanguageId));
    str                     labelId;
    Label                   label;

    AsciiIo                 file;
    ;

    dialog = new Dialog("@SYS69879");
    dialogFieldExcelFileName    = dialog.addField(extendedTypeNum(FileNameOpen));
    dialogFieldXPOFileName      = dialog.addField(extendedTypeNum(FileName));


    if (!dialog.run())
        return;

    excelFileName   = dialogFieldExcelFileName.value();
    xpoFileName     = dialogFieldXPOFileName.value();

    // Prepare output file
    file = new AsciiIo(xpoFileName, 'w');

    file.write('Exportfile for AOT version 1.0 or later');
    file.write('Formatversion: 1');
    file.write('');
    file.write('***Element: JOB');
    file.write('');
    file.write('; Microsoft Dynamics AX Job: Job1 unloaded');
    file.write('; --------------------------------------------------------------------------------');
    file.write('  JOBVERSION 1');
    file.write('');
    file.write('  SOURCE #DummyJob_DontImportMe');
    file.write('    #static void DummyJob_DontImportMe(Args _args)');
    file.write('    #{');
    file.write('    #}');
    file.write('  ENDSOURCE');

    // Create Excel object
    application = SysExcelApplication::construct();
    workBooks   = application.workbooks();
    workBooks.open(excelFileName);

    workSheets = application.worksheets();
    workSheet = workSheets.itemFromNum(1);

    cells = workSheet.cells();

    // Get language id's
    rowCounter      = 1;
    columnCounter   = 2;    // First column is the label id colum, so skip that

    cell = cells.item(rowCounter, columnCounter);

    while (cell.value().bStr() != '')
    {
        languageIdMap.insert(columnCounter, cell.value().bStr());

        columnCounter++;
        cell = cells.item(rowCounter, columnCounter);
    }

    maxColumn = columnCounter - 1; // Save info for how many columns we have

    // Read label lines
    rowCounter++;
    columnCounter = 1;
    cell = cells.item(rowCounter, columnCounter);

    while (cell.value().bStr() != '')
    {
        while (columnCounter <= maxColumn)  // Loop over the colums
        {
            cell = cells.item(rowCounter, columnCounter);
            if (cell.value().bStr() != '')
            {
                // First column is the label numer
                if (columnCounter == 1)
                {
                    labelId = cell.value().bStr();
                    print labelId;
                }
                else
                {
                    if (subStr(cell.value().bStr() ,1 ,1) != '@')
                    {
                        label = new Label(languageIdMap.lookup(columnCounter));

                        // Write label
                        file.write(@'<Table:Record name="TmpSysLabel"');
                        file.write(@"      xmlns:Table='urn:www.microsoft.com/Formats/Table'>");
                        file.write(@'    <Table:Field name="Language">' + languageIdMap.lookup(columnCounter) + @'</Table:Field>');
                        file.write(@'    <Table:Field name="Label">' + cell.value().bStr() + @'</Table:Field>');
                        file.write(@'    <Table:Field name="Description">' + label.extractComment(labelId) + @'</Table:Field>');
                        file.write(@'    <Table:Field name="LabelId">' + labelId + '</Table:Field>');
                        file.write(@'    <Table:Field name="SysLabelApplModule">0</Table:Field>');
                        file.write(@'    <Table:Field name="recVersion">0</Table:Field>');
                        file.write('</Table:Record>');
                    }
                }
            }
            columnCounter++;
        }
        rowCounter++;
        columnCounter = 1;
        cell = cells.item(rowCounter, columnCounter);
    }

    // Close file
    file = null;

    // Close Excel
    application.quit();

    info ("@SYS54623");
}

"Exportlabels2Exel"


// This job exports labels to an Excel file
static void Exportlabels2Excel(Args _args)
{
    SysExcelApplication     application;
    SysExcelWorkBooks       workBooks;
    SysExcelWorkSheets      workSheets;
    SysExcelWorkSheet       workSheet;
    SysExcelCells           cells;
    Counter                 rowCounter      = 1;
    Counter                 columnCounter   = 1;

    List                    languageList    = new List(extendedTypeNum(LanguageId));
    ListEnumerator          languageEnumerator;

    Set                     setLabelModules  = new Set(extendedTypeNum(LabelModuleId));

    Map                     labelObjectsMap = new Map(extendedTypeNum(LanguageId), types::Class);
    Label                   labelObject;
    Label                   labelMaster;
    Str                     labelId;
    ;

    // Add to this list, the language codes you want to expoort
    //languageList.addEnd('da');
    languageList.addEnd('en-gb');
    languageList.addEnd('en-us');
    //languageList.addEnd('sv');
    //languageList.addEnd('nb-no');

    // Add to this set, the label files you want to export
    setLabelModules.add('USR');

    // Create needed Label ojects
    languageEnumerator = languageList.getEnumerator();
    while (languageEnumerator.moveNext())
    {
        if (!labelMaster)
        {
            labelMaster = new Label(languageEnumerator.current());
        }
        labelObject = new Label(languageEnumerator.current());
        if (labelObject)
        {
            labelObjectsMap.insert(languageEnumerator.current(), labelObject);
        }
    }

    // Create Excel object
    application = SysExcelApplication::construct();
    application.visible(false);
    workBooks   = application.workbooks();
    workSheets  = workbooks.add().worksheets();
    workSheet   = workSheets.itemFromNum(1);

    cells = workSheet.cells();

    rowCounter      = 1;
    columnCounter   = 1;

    // Create header row
    cells.item(rowCounter, columnCounter).value("Label ID");

    languageEnumerator.reset();

    while (languageEnumerator.moveNext())
    {
        columnCounter++;
        cells.item(rowCounter, columnCounter).value(languageEnumerator.current());
    }

    // Search the master language
    try
    {
        labelId = labelMaster.searchFirst('');

        while (labelId)
        {
            if (setLabelModules.in(labelMaster.moduleId(labelId)))
            {
                rowCounter++;
                columnCounter = 1;
                cells.item(rowCounter, columnCounter).value(labelId);

                languageEnumerator.reset();
                while (languageEnumerator.moveNext())
                {
                    columnCounter++;
                    labelObject = labelObjectsMap.lookup(languageEnumerator.current());
                    cells.item(rowCounter, columnCounter).value(labelObject.extractString(labelId) ? labelObject.extractString(labelId) : '');
                }
            }
            labelId = labelMaster.searchNext();

        }

        application.visible(true);
    }

    catch
    {
        application.quit();
    }
    info ("@SYS54623");
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,231 Super User 2025 Season 2 on at

    Hi Phan,

    The script was written for AX2009 as stated in the blog. In AX2012 you need to replace the function 'extendedTypeNum' by 'extendedTypeStr'. That should solve this compilation error.

    I haven't checked the complete script if therr is any other code that will not compile in AX2012.

  • Community Member Profile Picture
    on at

    Hi Andre,

    I replace the function 'extendedTypeNum' by 'extendedTypeStr'. But still error, you can see that error on the picture i upload with question.

  • Verified answer
    Sohaib Cheema Profile Picture
    49,443 User Group Leader on at

    Hi Phan,

    • For Exporting labels, you are missing another important point. After using extendedTypeStr You should also convert it back to int. have a look at below statement.

      enum2int(extendedTypeStr(LanguageId))

    It’s very important to convert it back to int.

  • Community Member Profile Picture
    on at

    Hi Sohaib,

    Thanks for your help.

    I still have error with two line :

      dialogFieldExcelFileName    = dialog.addField(extendedTypeNum(FileNameOpen));           dialogFieldXPOFileName      = dialog.addField(extendedTypeNum(FileName));


    Error : Argument '_typeName' is incompatible with the required type.

  • Sohaib Cheema Profile Picture
    49,443 User Group Leader on at

    because extendedTypeNum is no more usable. you should be using 'extendedTypeStr'

    That's already highlighted in above reply.

    Moreover remember that I cannot trust Import code, given above, because its written in 2009 and I haven't tested myself in ax2012. So, for import process, again I would recommend you to read my blogpost and understand logic. For Export you can use above code with suggested changes

  • Community Member Profile Picture
    on at

    Thanks very much,

    Its working after follow your instruction.

    That's so great.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans