Reputation: 1442
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:
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
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
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