Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

method contains text constant

Posted on by 1,085

Hi,

i'm quite new on AX 2009 and X++ programming. 

Just started following Microsoft's official manuals and tutorials. 

 

I've got some doubts about variable declarations in classes. 

 

Say i have to declare a string constant for an info box title, "Text box example".

I declared it in the new() method, but compiler's best practices section says: "method contains text constants".

 

I've googled it but found little results about. How do you behave in such a scenario? 

Thank you in advance

ciao

*This post is locked for comments

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,064 Most Valuable Professional on at
    Re: method contains text constant

    It is a best practice to use labels for all texts shown to users. This check is not run for strings in single quotes, so you can use them for some internal, non-GUI values - e.g. COM class names (usually the best approach is to use such strings only in macros, so you have a single point of change).

    You can safely deactivate this BP check if you write something what won't be used in production (e.g. prototypes).

  • Velislav Marinov Profile Picture
    Velislav Marinov 75 on at
    Re: method contains text constant

    You can't use double quotes inside strings. You should use single quotes instead.

    For example:

     info(strFmt("%1, '%2'", 1, 2));

  • vv1984 Profile Picture
    vv1984 1,085 on at
    Re: method contains text constant

    Got it.

    So i basically have to use labels for that?

    What's the difference between single quote and double quote text in AX?

    Thank you

    ciao

  • Suggested answer
    Amir Nazim Profile Picture
    Amir Nazim 5,994 on at
    Re: method contains text constant

    it is the best practice error, you better not used the text in double quote, it will give you BP error. if you used like that you cant convert you text to some other language if you need to use your solution in some other language.

    better use Label Id or if you need to use the text then use the Macro or single quote text

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,232 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,064 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans