Total Pageviews

Search This Blog

Thursday, November 24, 2011

Tip - How to Retrieve AOS Instance name in Dynamics AX via X++ Code

One of my mates asked me how to retreive AOS Instance name through code. My first impression was that it should be somewhere in the Global Class. But, soon figured out I was wrong, then I jumped into Session Class which has a static method getAOSInstance() which retreives the instance number

The requirement here was to extract the instance name. Suddenly, it striked me, that in standard AX in Administration > Online Users form, the last column shows the AOS instance name.

So, the next step was to go through AOT > Forms > SysOnlineUsers > display method getAOSInstanceName() -  here the key is serverSessions.aosId and serverSessions.Instance_Name - combination of both will give you the aos instance.

//BP Deviation documented
display ServerId getAOSInstanceName(SysServerSessions serverSessions)
{
    ServerId            sid = '';
    str                 aosId, machineName, instanceName;
    int                 pos;
    #DEFINE.ATSYMBOL('@')
    ;
    aosId = serverSessions.aosId;
    instanceName = serverSessions.Instance_Name;
    pos = strfind(aosId, #ATSYMBOL, 1, strlen(aosId));
    machineName = substr(aosId, 1, pos-1);
    sid = instanceName + '@' + machineName;
    return sid;
}

Sometimes Googling within AX helps  Njoi  ;-)








1 comment:

Joris de Gruyter said...

You can also enable the AOS name to show in the status bar at the bottom (through user options). However, we found that the AOS name it shows there, is literally the one specified in your configuration file (AXC) and not the actual AOS. Since the AX client just uses the port and server name, but ignores the aos name in the AXC, you can have fun with that ;-)