Monday, September 30, 2013

Of Busy Schedules and (busier) Recurring Schedules!!

I was recently asked to create a schedule for multiple reports and jobs. Now, creating the schedule for one report is fairly simple. You login into the portal, navigate to the report that you would like to schedule, set the schedule options, and viola! You are all set.

Creating the schedule for multiple reports posed more of a challenge. I did not want to manually navigate to each report path and edit the schedule for each report when I could whip up a simple script for doing the same automatically. Little did I know that the simple script would turn out to be not-so-simple.

I had a looooooong list of requirements that pretty much included having the entire list of options available on the portal UI such as

  • Having the flexibility of being able to choose which of the output formats (HTML, PDF, XLS 2003, XLS 2007, CSV) would be needed for which report.
  • Having the flexibility of being able to choose if the report should be saved to the file system.
  • Having the flexibility of being able to choose if the report (link or attachment or both) should be emailed, and if yes then the list of email addresses.
  • And of course, the schedule (daily / weekly / monthly), start time, end time, recurrence pattern, etc.

The below code snippets are part of what I use to perform these operations. They are written in VB.NET. Some of the code is taken from the original Cognos SDK sample code. The part that is not, is mine.

Create a new Schedule object

            Dim newSched As New schedule()

Set up options to set the schedule start time and date, frequency / recurrence pattern, etc
These are available as methods under the newSched object which is of class schedule

For the schedule to work, the system has to have valid user credentials. Below code gets the user credentials. That would be the current logged on user through the SDK

getCredential is a function that I wrote to get the credential of the current logged on user

            Dim schedCred As credential = getCredential()
            Dim credentials As New baseClassArrayProp()
            credentials.value = New baseClass() {schedCred}
            newSched.credential = credentials

Save the report output. Note that this saves the output under the same report output and not as a reportView

            saveOutput.name = runOptionEnum.saveOutput
            saveOutput.value = True

Set schedule email options

            Dim deliveryOptionString As New deliveryOptionString
            deliveryOptionString.name = deliveryOptionEnum.subject
            deliveryOptionString.value = reportName

            Dim deliveryOptionAddrSMTPArray As New deliveryOptionAddressSMTPArray
            deliveryOptionAddrSMTPArray.name = deliveryOptionEnum.toAddress
            Dim addrSMTP As addressSMTP() = New addressSMTP(1) {}
            addrSMTP(0) = New addressSMTP
            addrSMTP(0).Value = "email@emailprovider.com"

            addrSMTP(1) = New addressSMTP
            addrSMTP(1).Value = "email2@emailprovider.com"

            deliveryOptionAddrSMTPArray.value = addrSMTP

            Dim deliveryOptionMemoPart As New deliveryOptionMemoPart
            deliveryOptionMemoPart.name = deliveryOptionEnum.memoPart

            Dim memoPart As New memoPartComposite
            memoPart.contentDisposition = smtpContentDispositionEnum.inline
            memoPart.contentType = smtpContentTypeEnum.alternative

            deliveryOptionMemoPart.value = memoPart

            Dim parts As memoPart() = New memoPart(1) {}

            Dim memoPartString As New memoPartString
            memoPartString.contentDisposition = smtpContentDispositionEnum.inline
            memoPartString.text = "Report Body"

            Dim memoPartMIMEAttachment As New memoPartMIMEAttachment
            memoPartMIMEAttachment.contentDisposition = smtpContentDispositionEnum.inline
            memoPartMIMEAttachment.dataType = "text/html"
            memoPartMIMEAttachment.dataSize = "0"

            Dim bArr() As Byte = System.Text.Encoding.UTF8.GetBytes("asdf")

            memoPartMIMEAttachment.data = bArr ' Byte array
            parts(0) = memoPartString
            parts(1) = memoPartMIMEAttachment

            emailAsAttachment.name = runOptionEnum.emailAsAttachment
            emailAsAttachment.value = True

            emailAsUrl.name = runOptionEnum.emailAsURL
            emailAsUrl.value = True

            email.name = runOptionEnum.email
            email.value = True

END Set schedule email options

Once the schedule email options are added, these options need to be added into an array of type 'option'.

Dim opts() As [option] = New [option](5) {}
            opts(0) = emailAsAttachment
            opts(1) = emailAsUrl
            opts(2) = deliveryOptionString
            opts(3) = deliveryOptionAddrSMTPArray
            opts(4) = deliveryOptionMemoPart
            opts(5) = email

Next, this options array will have to be added to the schedule object
           
            Dim schOpts As New optionArrayProp
            schOpts.value = opts
            newSched.options = schOpts

Finally, create a new schedule (or update an existing schedule) for the report / job by using the add method of the contentmanagerservice1 class

Thursday, March 14, 2013

Of stubborn wives and stubborn-er content stores

So it seems like I have been away for a long time. In my defense, I was busy. I got married and have been navigating the joys (and perils!!) of married life!!

The perils usually came when I had to work late on getting Cognos environments up for our customers and my stubborn wife insisted on staying up and keeping me company (shooting daggers at me all the time, mind it) while I was up troubleshooting issues with IBM ;-)

One such situation was when I had to work with IBM support on getting an environment up that refused to come up, no matter what we tried to do. The content store was on a Microsoft SQL Server environment and the startup process would complete successfully. The only exception was that the dispatcher would not complete initialization successfully.

The environment was a default install with all components installed and configured with the default settings. The dispatcher, gateway and content manager were set with the default settings. There was no configuration that was edited or customized.

All startup tasks would complete successfully. The content manager was initialized successfully. Even the BiBus process started successfully (doh!). I could see connections going from the content manager to the MS SQL content store.

We created a completely new content store on the same DB environment (to eliminate any environment problems) and Cognos started fine. This eliminated any issues with the app environment and left the db / content store environment.

We took a backup of the existing content db from MSSQL and recreated it on a completely separate environment. We then pointed an app environment to this content db and this started fine!

The problem that we had now was to get this back into our production environment. We did a regular full content store export from Cognos Administration and imported this export into the production environment.

To this day, we have no idea why the original production environment failed to start.

One important lesson that I learnt that day was that having a file level backup of the content db just wasn't enough. In addition to it, a full content store export as an additional backup is also a good idea.