Update: the below code works fine to put code in Prolog and Epilog.
It can be extended to do the Metadata and Data tabs as well.
But I don't seem to be able to set the datasource of the process to a text file or to a cube view.
In addition, setting parameters (numeric or string) is not achieved either.
Does anyone have some clues ? How do I translate CHARACTERDELIMITED as the data source to a value that the API likes ?
Code: Select all
Option Explicit
'Source: 'http://www.tm1forum.com/viewtopic.php?t=3355
Declare Sub TM1APIInitialize Lib "tm1api.dll" ()
Declare Sub TM1APIFinalize Lib "tm1api.dll" ()
Declare Function TM1SystemOpen Lib "tm1api.dll" () As Long
Declare Sub TM1SystemClose Lib "tm1api.dll" (ByVal hUser As Long)
Declare Sub TM1SystemAdminHostSet Lib "tm1api.dll" (ByVal hUser As Long, ByVal AdminHosts As String)
Declare Function TM1SystemServerConnect Lib "tm1api.dll" (ByVal hPool As Long, ByVal sServer As Long, ByVal sClient As Long, ByVal sPassword As Long) As Long
Declare Function TM1ValPoolCreate Lib "tm1api.dll" (ByVal hUser As Long) As Long
Declare Sub TM1ValPoolDestroy Lib "tm1api.dll" (ByVal hPool As Long)
Declare Function TM1ValString Lib "tm1api.dll" (ByVal hPool As Long, ByVal InitString As String, ByVal MaxSize As Long) As Long
Declare Function TM1ValArray Lib "tm1api.dll" (ByVal hPool As Long, ByRef sArray() As Long, ByVal MaxSize As Long) As Long
Declare Function TM1ValArrayGet Lib "tm1api.dll" (ByVal hUser As Long, ByVal vArray As Long, ByVal index As Long) As Long
Declare Function TM1ValArrayMaxSize Lib "tm1api.dll" (ByVal hUser As Long, ByVal vArray As Long) As Long
Declare Sub TM1ValArraySet Lib "tm1api.dll" (ByVal vArray As Long, ByVal val As Long, ByVal index As Long)
Declare Sub TM1ValArraySetSize Lib "tm1api.dll" (ByVal vArray As Long, ByVal Size As Long)
Declare Function TM1ServerProcesses Lib "tm1api.dll" () As Long
Declare Function TM1ProcessCreateEmpty Lib "tm1api.dll" (ByVal hPool As Long, ByVal hServer As Long) As Long
Declare Function TM1ProcessPrologProcedure Lib "tm1api.dll" () As Long
Declare Function TM1ProcessEpilogProcedure Lib "tm1api.dll" () As Long
Declare Function TM1ProcessCheck Lib "tm1api.dll" (ByVal hPool As Long, ByVal hProcess As Long) As Long
Declare Function TM1ProcessUpdate Lib "tm1api.dll" (ByVal hPool As Long, ByVal hOldProcess As Long, ByVal hNewProcess As Long) As Long
Declare Function TM1ObjectListHandleByIndexGet Lib "tm1api.dll" (ByVal hPool As Long, ByVal hObject As Long, ByVal iPropertyList As Long, ByVal iIndex As Long) As Long
Declare Function TM1ObjectListHandleByNameGet Lib "tm1api.dll" (ByVal hPool As Long, ByVal hObject As Long, ByVal iPropertyList As Long, ByVal sName As Long) As Long
Declare Function TM1ObjectPropertySet Lib "tm1api.dll" (ByVal hPool As Long, ByVal hObject As Long, ByVal Property_P As Long, ByVal ValRec_V As Long) As Long
Declare Function TM1ObjectDuplicate Lib "tm1api.dll" (ByVal hPool As Long, ByVal hObject As Long) As Long
Declare Function TM1ObjectDestroy Lib "tm1api.dll" (ByVal hPool As Long, ByVal hObject As Long) As Long
Declare Function TM1ObjectRegister Lib "tm1api.dll" (ByVal hPool As Long, ByVal hParent As Long, ByVal hObject As Long, ByVal sName As Long) As Long
Sub createEmptyProcess()
Call addProcess("adminhost", "tm1servername", "username", "password", "testprocedure")
End Sub
Public Function addProcess(ByVal sAdminHost As String, ByVal sServerName As String, _
ByVal sClientName As String, ByVal sClientPassword As String, ByVal sProcessName As String) As Boolean
Dim hUser As Long
Dim hServerName As Long, hClientName As Long, hClientPassword As Long, hProcessName As Long
Dim hServer As Long
Dim hPool As Long, hsPool As Long, hpPool As Long, hppPool As Long, hArrayPool As Long
Dim hArray As Long
Dim lArray() As Long
Dim NoParameters As Integer
Dim lReturn1, lReturn2, lReturn3, lReturn4, lReturn5, lReturn6, lReturn7, lReturn8, lReturn9 As Long
hUser = TM1SystemOpen()
hPool = TM1ValPoolCreate(hUser)
hsPool = TM1ValPoolCreate(hUser)
hpPool = TM1ValPoolCreate(hUser)
hppPool = TM1ValPoolCreate(hUser)
hArrayPool = TM1ValPoolCreate(hUser)
hServerName = TM1ValString(hsPool, Trim(sServerName), 0)
hClientName = TM1ValString(hsPool, Trim(sClientName), 0)
hClientPassword = TM1ValString(hsPool, Trim(sClientPassword), 0)
hProcessName = TM1ValString(hsPool, Trim(sProcessName), 0)
TM1SystemAdminHostSet hUser, sAdminHost
hServer = TM1SystemServerConnect(hPool, hServerName, hClientName, hClientPassword)
lReturn1 = TM1ProcessCreateEmpty(hpPool, hServer)
lReturn2 = TM1ObjectRegister(hpPool, hServer, lReturn1, hProcessName)
lReturn3 = TM1ObjectListHandleByNameGet(hpPool, hServer, TM1ServerProcesses, hProcessName)
lReturn4 = TM1ObjectDuplicate(hpPool, lReturn3)
Dim sCode_Prolog As String
Dim sCode_Epilog As String
sCode_Prolog = "§§§vDim = 'Account_PL';§DimensionCreate( vDim );"
NoParameters = 1
ReDim lArray(NoParameters)
hArray = TM1ValArray(hArrayPool, lArray(), NoParameters)
TM1ValArraySet hArray, TM1ValString(hsPool, Replace(sCode_Prolog, "§", vbCrLf), 0), 1
lReturn5 = TM1ObjectPropertySet(hppPool, lReturn4, TM1ProcessPrologProcedure, hArray)
sCode_Epilog = "§§§vCube = 'PL';§CubeSetLogChanges( vCube, 0 );"
NoParameters = 1
ReDim lArray(NoParameters)
hArray = TM1ValArray(hArrayPool, lArray(), NoParameters)
TM1ValArraySet hArray, TM1ValString(hsPool, Replace(sCode_Epilog, "§", vbCrLf), 0), 1
lReturn6 = TM1ObjectPropertySet(hppPool, lReturn4, TM1ProcessEpilogProcedure, hArray)
lReturn7 = TM1ProcessCheck(hpPool, lReturn4)
lReturn8 = TM1ProcessUpdate(hpPool, lReturn3, lReturn4)
lReturn9 = TM1ObjectDestroy(hpPool, lReturn4)
TM1ValPoolDestroy (hPool)
TM1ValPoolDestroy (hsPool)
TM1ValPoolDestroy (hpPool)
TM1ValPoolDestroy (hppPool)
TM1SystemClose (hUser)
TM1APIFinalize
End Function