Cognos 10 Report Studio Tutorial

Cognos Burst Report Dynamic Email Subject and File Name

In this article, we will learn How to Dynamically change email, mail subject, body and file name for Cognos Burst Report?
In our previous article, we learned How to Use Cognos Report Burst Option? When we used Cognos Report Burst all the recipient receive an email with the same subject, body, and file name. We want to change it and make it dynamic.

This article helps to answer following questions

  • How to change Cognos burst report file names?
  • How to change Cognos burst report email, mail subject and mail body?
  • How to use burst key in Cognos?
  • How to burst Cognos report to the file system?


Before Start check following videos.

  1. Configure SMTP : IBM Cognos SMTP Configuration
  2. Cognos Report Bursting
  3. Create your own SMTP Server for testing

The following image shows the before and after output.

If you need to learn Cognos Report Burst check this article.
For dynamic email, subject, body and file name first we need to modify some configuration files. If you don't have admin privileges then you need someone with IBM Cognos Administration privileges,
For the first setting open IBM Cognos Configuration. You can find it in IBM Cognos installation directory.

Save IBM Cognos Configuration and Restart the services. We need to save the report output to file system. Above change is for the same purpose. We need to save the report outputs on file system. We can use scripts to send email for reports stored on the file system. Next, we need to edit some configuration variables. For this follow steps showed in the following images.

First, open IBM Cognos Administration. Open properties for "ContentManagerService".

Click on the Settings tab and Edit Environment.

Override settings and add two parameters with respective values. Examples are for my machine setup
1. CM.OUTPUTLOCATION <OutPut Directory where you want to save your report output>
Ex: Parameter CM.OUTPUTLOCATION Value C:\Data\Reports\Output
2. CM.OUTPUTSCRIPT <Script files we need to run after reports are save on the file system>
Ex: Parameter CM.OUTPUTSCRIPT Value C:\Data\Reports\Output\RenameReport.bat

Above two parameters help us to control report output directory and script need to run after reports are saved in the mentioned directory. Next, we need to create "RenameReport.bat" file and "RenameReport.vbs" file. The batch file called VB Script. The VB Script rename all the report output available in the directory and send the renamed file to the respective users or email id.

Following is our Report Output Directory "C:\Data\Reports\Output" with following file and folder
File      RenameReport.bat – Call VB Script file
File      RenameReport.vbs – VB Script to rename and send email
Folder  Delete – Reports were delete and store inside this for cleaning purpose.

Why batch file and VB Script? We are using windows environment and we can use both without required to install any other software. You can also use C# or Java if you want to rename and sending the emails.

File Name: RenameReport.bat

@echo off
pushd %~dp0
cscript RenameReport.vbs


FileName: RenameReport.vbs

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"

Recurse objFSO.GetFolder("C:\Data\Reports\Output\")
Sub Recurse(objFolder)
    Dim objFile, objSubFolder
    For Each objFile In objFolder.Files
        If LCase(objFSO.GetExtensionName (objFile.Name)) = "xml" Then
            xmlDoc.Load (objFile.Name)
            Set Root = xmlDoc.documentElement
            If Not Root Is Nothing Then
                Set NodeList = Root.getElementsByTagName("burstKey")
                Dim BurstKey
                For Each Elem In NodeList
                BurstKey = Elem.text
                Set NodeList = Root.getElementsByTagName("fileName")
                Dim FileName
                For Each Elem In NodeList
                FileName = Elem.text  
                If objFSO.FileExists(objFSO.GetParentFolderName(WScript.ScriptFullName)+"\"+FileName) Then 
                    If objFSO.FileExists(objFSO.GetParentFolderName(WScript.ScriptFullName)+"\"+replace(BurstKey, " ", "")+"Gross_Profit."+objFSO.GetExtensionName(FileName)) Then
                        objFSO.DeleteFile objFSO.GetParentFolderName(WScript.ScriptFullName)+"\"+replace(BurstKey, " ", "")+"Gross_Profit."+objFSO.GetExtensionName(FileName)
                    End If
                    objFSO.MoveFile objFSO.GetParentFolderName(WScript.ScriptFullName)+"\"+FileName, objFSO.GetParentFolderName(WScript.ScriptFullName)+"\"+replace(BurstKey, " ", "")+"Gross_Profit."+objFSO.GetExtensionName(FileName)
                    'objFSO.DeleteFile objFSO.GetParentFolderName(WScript.ScriptFullName)+"\"+replace(BurstKey, " ", "")+"Gross_Profit."+objFSO.GetExtensionName(FileName)
                    Set objMsg = CreateObject("CDO.Message")
                    objMsg.Subject  = BurstKey + ": Gross Profit By Country "  & vbTab & Now()
                    objMsg.Sender = "noreply@localhost" 
                    objMsg.To =  replace(BurstKey, " ", "")+"@localhost"
                    objMsg.From      = "noreply@localhost"
                    objMsg.CC         = "mayanksanghvi@localhost"
                    objMsg.TextBody = "Hi, Please find the attached regional report." & vbTab & Now()
                    objMsg.AddAttachment objFSO.GetParentFolderName(WScript.ScriptFullName)+"\"+replace(BurstKey, " ", "")+"Gross_Profit."+objFSO.GetExtensionName(FileName) 'NOTE: DO NOT USE AN "=" SIGN AFTER "AddAttachment"
                    objMsg.Configuration.Fields.Item("") = 2
                    objMsg.Configuration.Fields.Item("") = "localhost"
                    objMsg.Configuration.Fields.Item("") = 25
                    objFSO.MoveFile objFSO.GetParentFolderName(WScript.ScriptFullName)+"\"+replace(BurstKey, " ", "")+"Gross_Profit."+objFSO.GetExtensionName(FileName), objFSO.GetParentFolderName(WScript.ScriptFullName)+"\Delete\"+replace(BurstKey, " ", "")+"Gross_Profit"+sprintf("{0:yyyyMMddhhmmss}", Array(now()))+"."+objFSO.GetExtensionName(FileName)
                    objFSO.MoveFile objFSO.GetParentFolderName(WScript.ScriptFullName)+"\"+objFile.Name, objFSO.GetParentFolderName(WScript.ScriptFullName)+"\Delete\"+sprintf("{0:yyyyMMddhhmmss}", Array(now()))+objFile.Name
                End If
            End IF
        End If

    For Each objSubFolder In objFolder.SubFolders
        Recurse objSubFolder
End Sub

Function sprintf(sFmt, aData)
   Dim g_oSB : Set g_oSB = CreateObject("System.Text.StringBuilder")
   g_oSB.AppendFormat_4 sFmt, (aData)
   sprintf = g_oSB.ToString()
   g_oSB.Length = 0
End Function


We can now run our report with following options

When Cognos Reports execution complete check Report Output directory.

Report output folder is empty, Why? Because of RenameReport.bat and RenameReport.vbs files. When report execution completed successfully, Cognos trigger RenameReport.bat file which triggers RenameReport.vbs. VB Script then loops through all the available files in Report Output directory and Send it to respective users. Then on success email respective file moved to Delete folder. Let's check the Delete folder.

In the delete folder, we have two sets of file one is report output which excels for the last execution and respective XML file. In XML file we have the following information for each report.

<?xml version="1.0" encoding="utf-8"?>
	<burstKey>United States</burstKey>
	<reportSearchPath>/content/folder[@name=&apos;Tutorials&apos;]/report[@name=&apos;Cognos Report Burst&apos;]</reportSearchPath>
	<reportViewSearchPath xsi:nil="true"/>


<?xml version="1.0" encoding="utf-8"?>
    <reportSearchPath>/content/folder[@name=&apos;Tutorials&apos;]/report[@name=&apos;Cognos Report Burst&apos;]</reportSearchPath>
    <reportViewSearchPath xsi:nil="true"/>


In the delete folder, we have two sets of file one is report output which excels for the last execution and respective XML file. In XML file we have the following information for each report.
We are interested in burstKey and fileName. Cognos Report execution output report name is “568_1525592978194.xlsx”. We renamed it to "AmericasGross_Profit20180507024032.xlsx" based on burstKey and send it to Americas@localhost. We can edit RenameReport.vbs to get the current email based on the burstkey.

Finally, we can check the email client for the email.


About The Author

Hello, I am Mayank Sanghvi I am primarily a BI developer with experience in MSBI and Cognos BI Suit. Also having interest in various other technologies such as Android, Java, C#, ASP .NET and other. I enjoy learning new technologies and share my experience with others.

Leave A Comment

Please login to post your valuable comments.