Using environment variables in AX

爱⌒轻易说出口 提交于 2019-12-11 05:46:35

问题


Is there any possibility to make use of windows-environment-variables in AX?

Example:

Property NormalImage on a MenuItem. I'd like to use sth. like %USERNAME% instead of the explicit username. In Classes for example I can use the WINAPI macro and refer to a user-folder-variable, eg CSIDL_MYPICTURES, to access the path per user. In AOT-object-properties there's no possibility to reference to macros...

Any way to achieve this?


回答1:


No, you can't do this on the AOT. You can change some properties on runtime through X++ code, but you can't dynamically change the image on a MenuItem as far as I know.

You can make visible/invisible some menuitems. May be can simulate what you are trying to do this way, although this is not quite aligned with the AX design patterns.




回答2:


Yes you can use .Net framework to get environment variables or you can use built in AX functions. See this example I typed up:

static void Job85(Args _args)
{
    System.String   systemString;
    str             marshalString;
    ;

    // Built in AX function
    info(strfmt("%1, %2, %3", xUserInfo::find().networkAlias, xUserInfo::find().networkDomain, xUserInfo::find().name));

    // .Net Framework
    systemString = System.Environment::GetEnvironmentVariable('username');
    marshalString = systemString; // Marshal it
    info(strfmt("%1", marshalString));
}

See http://msdn.microsoft.com/en-us/library/system.environment.getenvironmentvariable.aspx




回答3:


An example of getting the client name and machine name

static void testGetClientMachineName(Args _args)
{
    str localClientname, terminalServerName;
    ;
    localClientname = System.Environment::GetEnvironmentVariable('CLIENTNAME') ;
    info(localClientname);

    terminalServerName = System.Environment::get_MachineName();
    info(terminalServerName);

}


来源:https://stackoverflow.com/questions/14876443/using-environment-variables-in-ax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!