Using the Script Option to Rename PDF files to the Burst Key Value in Cognos ReportNet

waisttherapeuticΛογισμικό & κατασκευή λογ/κού

4 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

369 εμφανίσεις

Using the Script Option to Rename PDF files to the Burst Key Value in
Cognos ReportNet

Craig Taylor, Senior Support Engineer, Customer Support, Cognos, Ottawa, Ontario


Cognos ReportNet supports the ability to run a report and create PDF files in a folder instead of being stored in
Content Manager


however, the fil
es are stored with a unique number naming convention. For example:

498_1111538735180.pdf

498_1111538735180_desc.xml

In the case of a Burst Report, the burst key information is maintained in the XML file. The following technique
uses Microsoft Script Langua
ge to extract out the burst key information and rename the PDF file to the name of
the burst key.

The script will rename each bursted report to the key name. For example, if there are three burst key values


Montreal, London, and Berlin


three sets of fi
les will be created, each prefixed with a unique number followed by
a PDF extension and an XML extension. The script will run three times (once per saved report) and will extract
out the burst key information and rename the file to the burst key name:

498_
1111538735180.pdf > Montreal.pdf

498_1111538735181.pdf > London.pdf

498_1111538735182.pdf > Berlin.pdf

The first step is to use the Content Manager Service to save the PDF file to a folder and to instruct Cognos
ReportNet on which script file to run once
the PDF has been created:

1. In the Server Administration Page, display the services for Cognos ReportNet

2. Select the properties icon of the Content Manager Service

3. Click the setting Tab. The page should appear as shown below (directly following step
4).

4. Click the Edit… button to the right of Advanced settings


5. Add the following information for Parameter and Value …


… where CM.OUTPUTLOCATION is the name of the folder in which the report is saved and CM.OUTPUTSCRIPT is
the name of the batch file to run after creating the report. Af
ter adding this information, the advanced settings
should appear as follows:



The script as follow.


7. Create the BurstKey.bat file and save tha
t file in the D:
\
Reports folder. When the report is saved to the folder,
the batch file BurstKey.bat will be executed. This batch file creates a log file, sets two environment variables, and
calls the script file.

Contents of BurstKey.bat

@echo off

echo "B
urstKey Script" > d:
\
Report
\
Logs
\
batch.txt

echo Batch File Log >> d:
\
Report
\
Logs
\
batch.txt


rem Set the values for the PDF file and XML to environment

rem variables the reason for this is the scripting language

rem cannot read variables as param
eters

set parameter_pdf=%1%

set parameter_xml=%2%


rem Logs the variables to a batch log file

echo values set >> d:
\
Report
\
Logs
\
batch.txt

echo Parameter_pdf: %parameter_pdf% >> d:
\
Report
\
Logs
\
batch.txt

echo Parameter_xml: %parameter_xml% >> d:
\
Report
\
Lo
gs
\
batch.txt


rem Calls the script file

call d:
\
Report
\
burstKeyRename.vbs


echo Completed >> d:
\
Report
\
Logs
\
batch.txt




8. Create the burstKeyRename.vbs file and save that file in the D:
\
Reports folder. When the batch file is
executed, it will call th
is file. This script file burstKeyRename.vbs creates a log file, extracts the two environment
variables (PARAMETER_XML, PARAMETER_PDF), extracts the burst key information from the xml file, and then
renames the PDF file to the burst key name.

Contents of b
urstKeyRename.vbs

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set xmlDoc = CreateObject("MSXML.DOMDocument")

Set myErr = xmlDoc.parseError

Set WshShell = WScript.CreateObject("WScript.Shell")

Set WshSysEnv = WshShell.Environment("process")


' v
alues for Environment can be user, system, volatile and process

' the value process is the only valid one for this type of operation

Set WshSysEnv = WshShell.Environment("process")


' To check the value for process environment variable, this can be
tested
at

' the command prompt. Uncomment the next line and run this from command
line

' WScript.Echo WshSysEnv("parameter_xml")


' Initializing Variables


sList = "PDF Copy Log File " & vbTab & "Date: " & date & " " & time &
vbCrLf & vbCrLf & "Original Name" &


vbTab & "New Name" & vbCrLf

sLogFileName = "crn_pdf_rename.txt"

xFile = WshSysEnv("PARAMETER_XML") 'name of the XML
file

sFile = WshSysEnv("PARAMETER_PDF") 'name of the PDF
file

xmlDoc.async = False



iNode = 0


xmlDoc.Lo
ad xFile


If (xmlDoc.parseError.errorCode <> 0) Then



MsgBox("You have error " & myErr.reason)


Else



Set rootXML = xmlDoc.documentElement



Set oNodeList = rootXML.childNodes



For Each Item in oNodeList




If
xmlDoc.documentElement.childNodes.Item(iNod
e).basename = "burstKey"
Then





sNewFileName =
xmlDoc.documentElement.childNodes.Item(iNode).text




End If




iNode = iNode + 1



Next


End If


sNewFileName = sNewFileName & ".pdf"



' Copy the file to the new name


' Log the file names


sList = sList
& sFile & vbTab & sNewFileName & vbCrLf



objFSO.CopyFile sFile, sNewFileName



Set file = objFSO.CreateTextFile(sLogFileName)


If (objFSO.FileExists(sLogFileName)) Then



file.Write sList



file.Close


Else



sList = sLogFileName & " doesn't exist."



fi
le.Write sList



file.Close


End If


Set currentFolder = Nothing

Set objFSO = Nothing

Set file = Nothing

Set xmlDoc = Nothing

Set WshShell = Nothing

Set WshSysEnv = Nothing