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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Label Language

(0) ShareShare
ReportReport
Posted on by 6,648

Hi Guys,

when I use below code, lable string is shown;

static void labelId2String21(Args _args)
{
str value;
value = SysLabel::labelId2String2(literalstr('@SYS61013'), 'en-us');

info(value);
}

5707.333.png

But,when I use below code, name of variable(labelId) is shown;

static void labelId2String21(Args _args)
{
str value;
str labelId ='@SYS61013';

value = SysLabel::labelId2String2(literalstr(labelId), 'en-us');
info(value);
}

2146.555.png

As I haveto send "labelId" with parameter,How I solve this problem?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Label Language

    If you want to get the value of labelId variable and not the text "labelId", use labelId instead of literalstr(labelId).

  • Hossein.K Profile Picture
    6,648 on at
    RE: Label Language

    Hi Martin,

    it correct but some of label text involve (%) and I have to parse literal

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at
    RE: Label Language

    Did you try to remove literalstr call ?

  • Suggested answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Label Language

    That's a different problem - it's about what you assign to labelId variable (where you should use literalStr()), while your code means that you're not reading the variable at all.

  • Hossein.K Profile Picture
    6,648 on at
    RE: Label Language

    Martin,

    In fact, I want to fetch labeltext from labelId and transfer lt to cell of excel from this code:

    str labelId ='@SYS4005283';
    
    spreadSheet.AddStringCellToWorkbook( labelId , cellProperties);

    7870.000.png
    if I understood well, info() method, It does this conversion. Now in the excel is labelId instead of labeltext

  • Hossein.K Profile Picture
    6,648 on at
    RE: Label Language

    I want to fetch all of labelId and labeltext to excel.

    below is my job and result:

    // This job exports labels to an Excel file
    static void Exportlabels2Excel1(Args _args)
    {
        #define.ReadWritePermission('RW')
        #define.FileName(@'\\fileserver\test.xlsx')
        #define.ExcelColumnWidth(15)
        #define.ExcelCellFontSize("Microsoft.Dynamics.AX.Fim.Spreadsheets.CellFontSize")
        #define.Size9("Size9")
    
        Microsoft.Dynamics.AX.Fim.Spreadsheets.Spreadsheet spreadsheet;
        Microsoft.Dynamics.AX.Fim.Spreadsheets.CellProperties cellProperties;
        Microsoft.Dynamics.AX.Fim.Spreadsheets.ColumnProperties columnProperties;
    
        Counter                 rowCounter      = 1;
        Counter                 columnCounter   = 1;
    
        List                    languageList   =new  List(enum2int(extendedTypeStr(LanguageId)));
        ListEnumerator          languageEnumerator;
    
        Set                     setLabelModules  = new Set(enum2int(extendedTypeStr(LabelModuleId)));
    
        Map                     labelObjectsMap = new Map(enum2int(extendedTypeStr(LanguageId)), types::Class);
        Label                   labelObject;
        Label                   labelMaster;
        Description255                     labelId,language,label;
        str test
        ;
    
        new FileIOPermission(#FileName, #ReadWritePermission).assert();
    
        spreadSheet = new Microsoft.Dynamics.AX.Fim.Spreadsheets.Spreadsheet();
    
        if (!spreadSheet.CreateSpreadsheet(#FileName))
        {
            throw error(strFmt("@SYS72245", #FileName));
        }
    
        languageList.addEnd('en-us');
        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);
            }
        }
    
    
        rowCounter      = 1;
        columnCounter   = 1;
    
    
        languageEnumerator.reset();
    
        columnProperties = new Microsoft.Dynamics.AX.Fim.Spreadsheets.ColumnProperties();
        columnProperties.set_Width(#ExcelColumnWidth);
        spreadSheet.InstantiateColumn(columnProperties);
        cellProperties = new Microsoft.Dynamics.AX.Fim.Spreadsheets.CellProperties();
        cellProperties.set_FontSize(CLRInterop::parseClrEnum(#ExcelCellFontSize, #Size9));
        cellProperties.set_Bold(true);
        spreadSheet.AddStringCellToWorkbook("Lable Id", cellProperties);
    
    
        columnProperties = new Microsoft.Dynamics.AX.Fim.Spreadsheets.ColumnProperties();
        columnProperties.set_Width(#ExcelColumnWidth);
        spreadSheet.InstantiateColumn(columnProperties);
        cellProperties = new Microsoft.Dynamics.AX.Fim.Spreadsheets.CellProperties();
        cellProperties.set_FontSize(CLRInterop::parseClrEnum(#ExcelCellFontSize, #Size9));
        cellProperties.set_Bold(true);
        spreadSheet.AddStringCellToWorkbook("Lable name", cellProperties);
    
        try
        {
            labelId = labelMaster.searchFirst('');
    
            while (labelId)
            {
                spreadSheet.MoveToNextRowInWorkbook();
                cellProperties = new Microsoft.Dynamics.AX.Fim.Spreadsheets.CellProperties();
                cellProperties.set_FontSize(CLRInterop::parseClrEnum(#ExcelCellFontSize, #Size9));
    
                if (labelId)
                {
                    rowCounter++;
                    columnCounter = 1;
    
                    spreadSheet.AddStringCellToWorkbook(labelId, cellProperties);
                    //spreadSheet.AddStringCellToWorkbook(labelId, cellProperties);
                    spreadSheet.AddStringCellToWorkbook(literalstr(labelId), cellProperties);
                }
                labelId = labelMaster.searchNext();
    
            }
        spreadSheet.WriteFile();
        spreadSheet.Dispose();
    
        CodeAccessPermission::revertAssert();
    
        }
    
        catch
        {
    
        }
        info ("@SYS54623");
    }


    3872.zzz.png

  • Suggested answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Label Language

    You know about labelId2String2(), but you to use it in your first case.

    The latter one has again the old bug - literalstr(labelId). As discussed before, literalstr(labelId) returns text "labelId" and not the value of labelId variable, therefore the result you get is expected.

    By the way, let me remove the "Suggested answer" flag from your last reply, because it's describing a problem and not a solution.

  • Hossein.K Profile Picture
    6,648 on at
    RE: Label Language

    Well, what part of the code do I change?

    Can you tell me the correct code?

  • Verified answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Label Language

    This is your code:

    str labelId ='@SYS4005283';
    spreadSheet.AddStringCellToWorkbook(labelId, cellProperties);

    You said you got a label ID instead of the label text and you somehow forgot that you started this discussion with the method doing this conversion - labelId2String2(). You just have to add it:

    str labelText = SysLabel::labelId2String2(labelId, 'en-us');
    spreadSheet.AddStringCellToWorkbook(labelText, cellProperties);
  • Verified answer
    Hossein.K Profile Picture
    6,648 on at
    RE: Label Language

    Hi Martin,

    The problem is solved.you said correctly but more I had a problem in format label text in excel and which means excel file is crupted after run job.I solved this problem with help you and creating CSV file instead of Excel file ::))

    // This job exports labels to an Excel file
    static void Exportlabels2CSV(Args _args)
    {
    
        Microsoft.Dynamics.AX.Fim.Spreadsheets.Spreadsheet spreadsheet;
        Microsoft.Dynamics.AX.Fim.Spreadsheets.CellProperties cellProperties;
        Microsoft.Dynamics.AX.Fim.Spreadsheets.ColumnProperties columnProperties;
    
        Counter                 rowCounter      = 1;
        Counter                 columnCounter   = 1;
    
        List                    languageList   =new  List(enum2int(extendedTypeStr(LanguageId)));
        ListEnumerator          languageEnumerator;
    
        Set                     setLabelModules  = new Set(enum2int(extendedTypeStr(LabelModuleId)));
    
        Map                     labelObjectsMap = new Map(enum2int(extendedTypeStr(LanguageId)), types::Class);
        Label                   labelObject;
        Label                   labelMaster;
        Description255                     labelId,language,label;
        str test;
        str value;
        str lang;
        CommaIO commaIO;
        FileName fileName;
        ;
        
        fileName = "D:\\test.csv"; //Destination of the file
        commaIO = new CommaIO(fileName,'W');
        
        lang = 'en-gb';
        //new FileIOPermission(#FileName, #ReadWritePermission).assert();
    
    
    
        languageList.addEnd(lang);
        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);
            }
        }
    
    
        rowCounter      = 1;
        columnCounter   = 1;
    
    
        languageEnumerator.reset();
    
        commaIO.write("Lable Id","Lable name"); //Header of the CSV File
    
        try
        {
            labelId = labelMaster.searchFirst('');
    
            while (labelId)
            {
                if (labelId)
                {
                    value = "'"+SysLabel::labelId2String2(labelId, lang)+"'";
                    //value = strReplace(value,"%","");
                    commaIO.write(labelId,value);
                }
                labelId = labelMaster.searchNext();
            }
    
    
         CodeAccessPermission::revertAssert();
         WINAPI::shellExecute(fileName); 
        }
    
        catch
        {
    
        }
        info ("@SYS54623");
    }

    csv.png
      

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans