Eric S
Eric S

Reputation: 1442

AX 2012 - Get Instance Name not Server Name in X++

Is it possible to get the Instance Name instead of the Server Name in X++?

The attached image shows the field I am looking for:

AX Config

When I use xSession.AOSName(); it returns the Server Name and when I use sysServerSessions..Instance_Name; an empty string is returned. The Instance_Name field only has "01" in the database so it would still be incorrect if it did return a value.

Upvotes: 0

Views: 5488

Answers (2)

Eric S
Eric S

Reputation: 1442

Below is the added logic to Alex's answer to get the Instance Name.

static server str getAOSInstanceName()
{
    str serverPath;
    str instanceName;

    int fullPathLen;
    int serverNameEnd;
    int instanceNameStart;

    //Get the full path of the AOS Server install.
    serverPath = xInfo::directory(DirectoryType::Bin);

    fullPathLen = strLen(serverPath);

    //Get the location of where the Instance Names Ends. "-5" represents "\bin\" in the full path.
    serverNameEnd = fullPathLen - 5;

    //Get the location where the Instance Name Starts - 1.
    instanceNameStart = strFind(serverPath, @"\", serverNameEnd, - fullPathLen);

    //Get the Instance Name.
    instanceName = subStr(serverPath, instanceNameStart + 1, serverNameEnd - serverNameStart);

    return instanceName;
}

Upvotes: 0

Alex Kwitny
Alex Kwitny

Reputation: 11544

The Instance name (optional), I believe is just the folder name and the service display name. So when you create multiple instances, it creates a folder C:\Program Files\Microsoft Dynamics AX\60\Server\[InstanceName]\, and then an AOS service with that instance display name.

If you really want it, you could enumerate the folder and parse it using a regular expression or any number of other methods. To enumerate the folder, create this server static method somewhere and call it:

static server FilenameOpen pathServer()
{
    return xInfo::directory(DirectoryType::Bin);
}

There is also a ServerId, which I don't think is the same as the Instance Name, but it's in the SysServerConfig table:

while select sysServerConfig
{
    info(strFmt("%1", sysServerConfig.ServerId));
}

And the ServerId is a derived value from the AOSId and name, etc. You can see how it's derived in this method: \Data Dictionary\Tables\SysServerConfig\Methods\delete

Upvotes: 4

Related Questions