NT server automatically collected

Post Reply
Darkhorse
Posts: 141
Joined: Wed Mar 09, 2011 1:25 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2003 2007 2010 2013

NT server automatically collected

Post by Darkhorse »

Hi all

about a year ago i downloaded a tool from this site for running TIs from an Excel macro, It works brilliantly however it requires the manual addition of the NTserver, and TM1 server names, I managed to locate a way to automatically collect the Tm1 servername, is there a way i can automatically detect the NTserver names for the TM1 sever selected?

Tm1 server name Tm1_Profit
NTserver HPWRT324

Thanks to all that read

http://www.bihints.com/tm1_sdk

Code: Select all

'**********************************************************************************************
'** J.Wakefield InfoCat 09/11/01
'** A class that can be used to execute Process and Chores on a TM1 Serever
'**********************************************************************************************
Option Explicit
Option Base 1

Private hUser As Long
Private hPool As Long
Private hServer As Long

Private m_NTServer As String
Private m_TM1Server As String
Private m_User As String
Private m_Password As String
Private m_ChoreName As String
Private m_ProcessName As String
Private m_Parameter1 As String
Private m_Parameter2 As String
Private m_Parameter3 As String
Private m_Parameter4 As String
Private m_Parameter5 As String
Private m_NoParameters As Integer
Private m_ErrString As String
'***********************************************************************************
Public Property Get ntserver() As String
    ntserver = m_NTServer
End Property
'***********************************************************************************
Public Property Let ntserver(ByVal New_NTServer As String)
    m_NTServer = New_NTServer
End Property
'***********************************************************************************
Public Property Get tm1server() As String
    tm1server = m_TM1Server
End Property
Alan Kirk
Site Admin
Posts: 6667
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: NT server automatically collected

Post by Alan Kirk »

Darkhorse wrote: about a year ago i downloaded a tool from this site for running TIs from an Excel macro, It works brilliantly however it requires the manual addition of the NTserver, and TM1 server names, I managed to locate a way to automatically collect the Tm1 servername, is there a way i can automatically detect the NTserver names for the TM1 sever selected?

Tm1 server name Tm1_Profit
NTserver HPWRT324

Thanks to all that read

http://www.bihints.com/tm1_sdk
I'm aware of, but must admit that I've never really looked, at James Wakefield's code[1] so I'm not at all sure why it's requiring the server box's name. It's not needed to run a TI from the API.

If it's in fact looking for the name of the Admin Host (which you do need to connect to the API if you aren't piggy-backing off the TM1_API2HAN function in a logged-in Excel session), it's going to depend on which environment you're doing it in. If it's in VBA within Excel, the Application.Run("OptGet","AdminHost") macro function should do it. I'm not sure that it will in other VBA environments like Access though. (I've always supplied that value in Access code, or had it input via a form.) In fact I'd be surprised if it did, and doubly so in a stand alone VB6 application. (I don't really write in VB6 any more so I can't (more precisely won't) test that. In my VB.Net apps that use the API, I still have the Admin Host as an input in the application's configuration form. Trying to locate what the user's admin host might be (especially if they don't use TM1 via the classic interface and therefore may not have a complete tm1p.ini file) was frankly more trouble than it was worth.)

If you are running the code on the server itself, you can of course obtain the name of the computer via the:

Code: Select all

Environ$("ComputerName")
command.

Of course that comes with the proviso that it depends on what the name is to be used for. Again if it's the admin host that the code is seeking, the value will only be valid if the admin server is running on the same machine.

----------------------
[1] Technically, I looked at it when I was a newbie lo those many years ago but it may as well have been written in Sanskrit at the time since I had no knowledge of the API then, and the API is hardly the most user-friendly environment in the world. Obviously none of it stuck so I stand by my statement that I'm not sure why it's after that information.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Darkhorse
Posts: 141
Joined: Wed Mar 09, 2011 1:25 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2003 2007 2010 2013

Re: NT server automatically collected

Post by Darkhorse »

Thanks Alan,

You are 100% correct I am after the adminhost name (sorry was a late night when i posted) and agreed Alan this SDK kit i found this program in is very erm.. confusing but it was my first attempt at building outside in excel and unfortunately I entwined it quite heavily into a program toolbar and dont have the time to pick it apart and remove it.

However.. saying this i have been looking into your work and api writing vb code and was wondering if i could use your code

Function ReturnServerList(ListOfServers() As String) As Integer
'V1.0 Alan Kirk 15-Jan-10

could i add the ability to collect the admin host in this coding?


Code: Select all

Function ReturnServerList(ListOfServers() As String) As Integer
'V1.0 Alan Kirk 15-Jan-10
'Returns a list of the TM1 servers that are
'currently visible to the user. Can only be used in an Excel
'session with the TM1 add-in loaded since it piggy-backs
'using the TM1_API2HAN function. The user does not need
'to be logged in for this function to work, but will need
'be to return additional information from other functions.
'*** NOTE ***
'This procedure will return any runtime errors. Ensure that there
'is error handling in the calling procedure.

Dim b_ReraiseError As Boolean

Dim hUser As Long

Dim l_ServersIdx As Long
'Normally I'd use a Long here but the API function definition is Integer
'and it's too flaky to take chances.
Dim i_ServersCnt As Integer
Dim s_ServerName As String * 100

ReturnServerList = 0

On Error Resume Next
ReDim ListOfServers(-1)
On Error GoTo ErrorHandler

'Get the user handle.
hUser = TM1_API2HAN

'Equivalent to pressing [F5] in Server Explorer.
TM1SystemServerReload hUser

i_ServersCnt = TM1SystemServerNof(hUser)

If i_ServersCnt > 0 Then
    ReDim ListOfServers(i_ServersCnt - 1)
End If

For l_ServersIdx = 1 To i_ServersCnt
    'Reinitialise the string because the system server name function doesn't.
    'If you don't do that you can have the residue from past calls left over.
    s_ServerName = String(100, Chr$(0))

    TM1SystemServerName_VB hUser, l_ServersIdx, s_ServerName, 100

    ListOfServers(l_ServersIdx - 1) = TrimNull(s_ServerName)

Next

ReturnServerList = i_ServersCnt

ExitPoint:

On Error Resume Next

'DO NOT CALL TM1SystemClose HERE IF YOU VALUE THE STABILITY OF YOUR EXCEL SESSION!
'TM1APIFinalize
On Error GoTo 0

If b_ReraiseError Then

    Err.Raise ml_ErrNo, , ms_ErrDesc

End If

Exit Function

ErrorHandler:
If Err.Number <> vbObjectError + 1000 Then
    b_ReraiseError = True
    ml_ErrNo = Err.Number
    ms_ErrDesc = "Server list; " & Err.Description
End If

Resume ExitPoint

End Function
Alan Kirk
Site Admin
Posts: 6667
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: NT server automatically collected

Post by Alan Kirk »

Darkhorse wrote: However.. saying this i have been looking into your work and api writing vb code and was wondering if i could use your code

Function ReturnServerList(ListOfServers() As String) As Integer
'V1.0 Alan Kirk 15-Jan-10

could i add the ability to collect the admin host in this coding?
Unfortunately not. The problem is embedded in the commentary at the top:
Darkhorse wrote:

Code: Select all

Function ReturnServerList(ListOfServers() As String) As Integer
'V1.0 Alan Kirk 15-Jan-10
'Returns a list of the TM1 servers that are
'currently visible to the user. Can only be used in an Excel
'session with the TM1 add-in loaded since it piggy-backs
'using the TM1_API2HAN function. The user does not need
'to be logged in for this function to work, but will need
'be to return additional information from other functions.
'*** NOTE ***
'This procedure will return any runtime errors. Ensure that there
'is error handling in the calling procedure.
The code in question uses TM1_API2HAN, which is only valid in an Excel session. The thing about TM1_API2Han is that it returns a handle to a user session which (for want of a better term) has the admin host name "embedded" in it. (It has to have, because the connection that the user has made to TM1 in Excel can only be made if the Admin Host is specified in their options so that the server list can be displayed.)

If you can't use TM1_API2HAN (which I don't believe you can outside of Excel) then the only way (AFAIK) that the API can determine the Admin Host name is by it being fed to it via the TM1SystemAdminHostSet function.

I'm afraid that it's a "cause and effect" situation; one way or another the admin host has to be specified before a connection can be made. You can't make a connection, then recover the admin host from it.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Darkhorse
Posts: 141
Joined: Wed Mar 09, 2011 1:25 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2003 2007 2010 2013

Re: NT server automatically collected

Post by Darkhorse »

I am doing this in excel, and this list of servers out puts to an excel sheet column, once I have this list could I not loop through the list to find the adminhost of each server or am I being daft and have you just answered that?
Alan Kirk
Site Admin
Posts: 6667
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: NT server automatically collected

Post by Alan Kirk »

Darkhorse wrote:I am doing this in excel, and this list of servers out puts to an excel sheet column, once I have this list could I not loop through the list to find the adminhost of each server or am I being daft and have you just answered that?
I'm afraid that I did, but you need to be clear about whether you're staying in the Excel environment or not. I can only reiterate that there is a huge difference between Excel, and non-Excel environments.

The easiest way to get the list of Admin Hosts within Excel is still the Application.Run("OptGet","AdminHost") macro. This will get you the list of all Admin Hosts. It will not get you the admin host associated with any specific server.

(Though you can of course do that the other way around; that is, by parsing the list of Admin Hosts returned from the macro, then setting each one in turn using TM1SystemAdminHostSet and obtaining the list of servers associated with each admin host.)

Alternatively, if you are obtaining the user handle from TM1_API2HAN then I would imagine (I haven't actually tried it) that you would be able to obtain the list of Admin Hosts from TM1SystemAdminHostGet_VB. However this would be an entirely redundant exercise since TM1_API2HAN already supplies the connection with all the information it needs about the Admin Host so there is no actual need to ever pass that value to any API code.

If you are planning on writing code outside of Excel, though, neither of the above options exist. In a non-Excel environment:
- The only way you will ever get the list of servers in the first place is if the connection has obtained the list from the Admin Server; and
- The only way the connection can get that list is if it has already been told the Admin Host so that it can query the Admin Server and ask it which servers are registered with it.

Outside of Excel TM1SystemAdminHostGet_VB is only ever going to work if you have already passed the value originally using TM1SystemAdminHostSet. Catch 22, I'm afraid.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Post Reply