CognosTalk
Technical User
I created a bat file to automate cube build; somehow it is not functioning properly. It is calling the transformer and dying after. signon and automatic login is enabled in the model.
Any thoughts?
Any thoughts?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Main()
Dim objOutlookEmail as Object
Dim objTransApp As Object
Dim objModel As Object
Dim objDimension As Object
Dim objCategory As Object
Dim strTo As String
Dim strSubject As String
Dim strBody As String
Dim Logfile as string
'
Logfile = "E:\Logs\CognosLog.csv"
Open Logfile For APPEND As #1
Write #1, Format(DATE,"yyyy-MM-dd"),Format(Time,"HH:mm:ss"), "Stock Start"
Close #1
'
On Error goto ErrMes 'If problem, email & then exit
'
PART_I: 'Open and build cube
Set objTransApp = CreateObject("CognosTransformer.Application")
Set objModel = objTransApp.OpenModel("E:\PPModels\Stock.pyi","Administrator","Password","Root User Class")
Set objDimension = objModel.Dimensions.Item("All Dates")
Set objCategory = objDimension.Categories(2)
With objCategory
' set current calendar year and include right months
.Name = "Calendar Year" & str(year(Cvar(date)-1))
.RunningPeriods = month(cvar(date)-1)
.Update
End With
With objModel
.CreateMDCFiles
.Update
.SaveAs "E:\PPModels\Stock_Run.pyi"
.Close
End With
Set objDimension = Nothing
Set objCategory = Nothing
Set objModel = Nothing
Set objTransApp = Nothing
'
PART_II: 'Switch cube into live between stopping and starting PPES
Shell ("E:\batch_files\kill_stock_cube.bat")
sleep 10000
FileCopy "E:\cubes\Stock.mdc", "E:\Live_Cubes\stock.mdc"
sleep 10000
Shell ("D:\batch_files\enable_stock_cube.bat")
'
PART_III: 'create and send email
strSubject = "Stock cube"
strBody = "Now built. This has been an automated message."
strTo = "lex.luthor@acme.com"
Set objOutlookEmail = CreateObject("CDONTS.NewMail")
with objOutlookEmail
.From = "Cognos@Acme.com"
.To = strTo
.Subject = strSubject
.Body = strBody
.MailFormat = 0
.Send
End with
set objOutlookEmail = nothing
'
endmac:
Open Logfile For Append As #1
Write #1, Format(DATE,"yyyy-MM-dd"),Format(Time,"HH:mm:ss"), "Stock End"
Close #1
Exit Sub
'
ErrMes:
strTo = "lex.luthor@Acme.com"
strSubject = "Stock macro FAILURE"
strBody = "Please note that the cube build failed with error " & Err & " : " & Error$ & " which occurred at line: " & Erl
If weekday(CVar(DATE))=1 or weekday(CVar(DATE))=7 then strSubject = strSubject + " at the weekend"
'
Set objOutlookEmail = CreateObject("CDONTS.NewMail")
with objOutlookEmail
.To = strTo
.From = "Doomsayer@Acme.com"
.Subject = strSubject
.Body = strBody
.MailFormat = 0
.Send
End with
set objOutlookEmail = nothing
Open Logfile For Append As #1
Write #1, Format(DATE,"yyyy-MM-dd"),Format(Time,"HH:mm:ss"), "Error " & Err & " @ line: " & Erl & " - " & Error$
Close #1
Resume endmac
End Sub