How to refresh Cognos PowerPlay cube using CognosScipt
A simple example of a cognos macro to refresh the cubes in a model:
Sub Main () Dim objTransapp As Object Dim objModel As Object Dim strModelSource As string strModelSource = "D:\cognos\gg\etltools_model.pyi" Set objTransapp = CreateObject("CognosTransformer.Application") Set objModel = objTransapp.OpenModel(strModelsource,"admin","","Root User Class") Objmodel.CreateMdcFiles objModel.close End Sub
The most significant command in the script attached above is the Objmodel.CreateMdcFiles command which actually creates the MDC files.
To make a refresh program more stable, it may be a good idea to add some error handling. It is also possible to extract some basic info from the newly created PowerCubes (msgbox statements). It can be done this way:
Sub Main () 'Set error handling. ON ERROR GOTO ERRORHANDLE Dim objTransapp As Object Dim objModel As Object Dim objCube As Object Dim strModelSource As string strModelSource = "D:\cognos\gg\etltools_model.pyi" Set objTransapp = CreateObject("CognosTransformer.Application") Set objModel = objTransapp.OpenModel(strModelsource,"admin","","Root User Class") Objmodel.CreateMdcFiles Set objCube = objModel.Cubes.Item(1) Msgbox objCube.MDCFile Msgbox format(objCube.CubeStamp,"yyyy-mm-dd") Msgbox objCube.CubeCreation objModel.close Set objmodel = Nothing Set objTransApp = Nothing Done: Exit Sub ERRORHANDLE: Msgbox "Error occurred!" & chr(10) & "Error Description: " & Error$ & _ Chr(10) & "Number: " & Err & chr(10) & "Line: " & str$(Erl) End Sub
We recommend to follow up with the following article: