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?
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.
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
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);
}