Conditional formatting rules are an everyday part of reporting via BusinessObjects WEBi… But finding out what the colouring rules behind a report are is still a horribly manual process.
You can use your newfound scripting abilities to combat this… In this tutorial, we’ll be covering how to discover the conditions and formats behind an alerter.
Assumptions are that you’re now familiar with connecting to the platform via the REST web service and are able to search for a document based on it’s ID… If not, I suggest you recap some earlier posts on this.
Well, first thing’s first… Here’s the whole script:
######################################################################################################################################################### # Log on to BI platform $LogonRequestUri = "http://BOEServer:6405/biprws/logon/long" $LogonRequestHeaders = @{"Accept" = "application/json";"Content-Type" = "application/json"} $LogonInfo = @{} $LogonInfo.userName = "developmentish" $LogonInfo.password = "password" $LogonInfo.auth = "secEnterprise" $Logon = ($LogonInfo | ConvertTo-Json) $LogonToken = "`"" + (Invoke-RestMethod -Method POST -Uri $LogonRequestUri -Headers $LogonRequestHeaders -Body $Logon).logonToken + "`"" ######################################################################################################################################################### # Make a request # Do this for a report ID I already know $ReportID = 706729 # And AlerterID 6 - You'll need to discover which ID you want by running a get on the ../documents/reportID/alerters URL without the /ID at the end. $AlerterID = 6 $DocRequestUri = "http://BOEServer:6405/biprws/raylight/v1/documents/$ReportID/alerters/$AlerterID" $DocRequestHead = @{"Accept" = "application/json";"ContentType" = "application/json";"X-SAP-LogonToken" = $LogonToken} # Run the rest URL and save the results as a variable $RestResult = Invoke-RestMethod -Method GET -Uri $DocRequestUri -Headers $DocRequestHead ######################################################################################################################################################### # Log off of BI Platform $LogoffRequestUri = "http://BOEServer:6405/biprws/logoff" $LoggoffRequestHeaders = @{"Accept" = "application/json";"X-SAP-LogonToken" = $LogonToken} Invoke-RestMethod -Method POST -Uri $LogoffRequestUri -Headers $LoggoffRequestHeaders ######################################################################################################################################################### # Working with our web service result # Create a system object for the result so we can add custom properties to our output $input = New-Object System.Object # Add various properties to our object... Multiple values will appear in @{} brackets... This happens if your alerter has multiple conditions & formats $Input | Add-Member -MemberType NoteProperty -Name ID -Value $RestResult.alerter.id $Input | Add-Member -MemberType NoteProperty -Name Name -Value $RestResult.alerter.name $Input | Add-Member -MemberType NoteProperty -Name Description -Value $RestResult.alerter.description $Input | Add-Member -MemberType NoteProperty -Name Condition -Value $RestResult.alerter.rule.conditions.condition $Input | Add-Member -MemberType NoteProperty -Name Background -Value $RestResult.alerter.rule.action.style.background.color $Input | Add-Member -MemberType NoteProperty -Name Font -Value $RestResult.alerter.rule.action.style.font # Display the result in the console $Input
So we need to look at what’s going on here… Lets start with our request:
# Do this for a report ID I already know $ReportID = 706729 # And AlerterID 6 - You'll need to discover which ID you want by running a get on the ../documents/reportID/alerters URL without the /ID at the end. $AlerterID = 6 $DocRequestUri = "http://BOEServer:6405/biprws/raylight/v1/documents/$ReportID/alerters/$AlerterID" $DocRequestHead = @{"Accept" = "application/json";"ContentType" = "application/json";"X-SAP-LogonToken" = $LogonToken} # Run the rest URL and save the results as a variable $RestResult = Invoke-RestMethod -Method GET -Uri $DocRequestUri -Headers $DocRequestHead
This shows us doing a GET request to the REST URL ../Documents/[whatever our reportID is]/alerters/[Whatever our alerterID is].
Before I built this URL I ran ../documents/[ReportID]/alerters and looked at the results and picked which alerter I wanted… I could have easily ran that and looped through the result set with a ForEach-Object{} loop too if I wanted all alerters for a document.
After I’ve pulled the results of my REST request, I saved them under the variable $RestResult then logged off of the platform to release the session.
At the bottom of the script I’ve manipulated my result and pushed various parts of it into properties of an empty object (this just looks nice when displaying it on screen)
# Create a system object for the result so we can add custom properties to our output $input = New-Object System.Object # Add various properties to our object... Multiple values will appear in @{} brackets... This happens if your alerter has multiple conditions & formats $Input | Add-Member -MemberType NoteProperty -Name ID -Value $RestResult.alerter.id $Input | Add-Member -MemberType NoteProperty -Name Name -Value $RestResult.alerter.name $Input | Add-Member -MemberType NoteProperty -Name Description -Value $RestResult.alerter.description $Input | Add-Member -MemberType NoteProperty -Name Condition -Value $RestResult.alerter.rule.conditions.condition $Input | Add-Member -MemberType NoteProperty -Name Background -Value $RestResult.alerter.rule.action.style.background.color $Input | Add-Member -MemberType NoteProperty -Name Font -Value $RestResult.alerter.rule.action.style.font # Display the result in the console $Input
Alternatively you could have explored this result object yourself and retrieve only the parts you’re interested in.
You can use this method for getting the details of an alerter and programmatically adding the rule to other documents for example. We may cover that in future sessions.
Enjoy!