Hi,
I am trying to get a list of all reports linked to a given package.
In our Cognos 8.2 implementation the reports are organised into departmental folders, and are
not stored within the associated package folders.
I am new to the SDK, and have experimented with the VB6 code below. The basic steps are:
1. Query the Content Store for a list of all reports
2. For those reports which are linked to the given package, record and display the name
The code works, however it actually returns no report names because our reports are not stored within the package folders. The SDK documentation states the following of the packageBase property:
QuoteIf the object is not a descendant of a package, the value of this property is the path to the root
object.
Thus the problem is that the basePackage property value actually returns the root path i.e. "/", and never the package name.
I guess I need to use another approach for this task, so am grateful for any assistance.
Cheers.
Private Sub List_Reports()
Dim oCM As ContentManagerService
Dim sUserID As String
Dim sPassword As String
Dim sNamespace As String
Dim sPath As New SearchPathMultipleObject
Dim oSortOptions As New SortC
Dim oQueryOpts As New QueryOptions
Dim oProps As New PropEnumC
Dim oReports As BaseClassC
Dim i As Integer
Dim sReports As String
On Error GoTo Exception:
' connection credentials
sUserID = "username"
sPassword = "password"
sNamespace = "namespace"
' connect to Content Manager
Set oCM = New ContentManagerService
oCM.endPointUrl = "http://localhost:9300/p2pd/servlet/dispatch"
Call oCM.logon(XMLEncode("<credential><namespace>" & sNamespace & _
"</namespace><username>" & sUserID & _
"</username><password>" & sPassword & _
"</password></credential>"), Nothing)
' define query search path parameters
sPath.Value = "//report"
oProps.Add defaultName
oProps.Add packageBase
' query Content Manager
Set oReports = oCM.Query(sPath, oProps, oSortOptions, oQueryOpts)
' iterate through reports
For i = 1 To oReports.Count
' look for package
If oReports.Item(i).packageBase.Value = "PackageName" Then
' record report name
sReports = sReports & oReports.Item(i).defaultName.Value & vbCrLf
End If
Next i
' show reports
MsgBox sReports
Exit Sub
Exception:
MsgBox Err.Description
End Sub
For those interested. This is how I resolved this...
Private Sub cmdExecute_Click()
Dim sPath As New SearchPathMultipleObject
Dim oSortOptions As New SortC
Dim oSortOption As New Sort
Dim oQueryOpts As New QueryOptions
Dim oProps As New PropEnumC
Dim oReports As BaseClassC
Dim oQueryOptProps As New PropEnumC
Dim oRefMetaProps As New RefPropC
Dim oRefMetaProp As New RefProp
Dim oAuthoredReport As AuthoredReport
Dim i As Integer
Dim oFSO As New FileSystemObject
Dim oTxt As TextStream
Dim sPackageName As String
Dim sOutput As String
On Error GoTo Exception:
Screen.MousePointer = vbHourglass
' define query search path parameters
sPath.Value = "//report"
oProps.Add defaultName
oProps.Add searchPath
' define query option properties
oQueryOptProps.Add defaultName
' define reference object properties
Set oRefMetaProp.properties = oQueryOptProps
oRefMetaProp.refPropName = metadataModelPackage
oRefMetaProps.Add oRefMetaProp
' assign reference properties
Set oQueryOpts.refProps = oRefMetaProps
' specify sort option settings
oSortOption.propName = defaultName
oSortOption.Order = ascending
oSortOptions.Add oSortOption
' query Content Manager
Set oReports = oCM.Query(sPath, oProps, oSortOptions, oQueryOpts)
' iterate through reports
For i = 1 To oReports.Count
Set oAuthoredReport = oReports.Item(i)
sPackageName = oAuthoredReport.metadataModelPackage.Value.Item(1).defaultName.Value
If sPackageName = txtPackageName Then
' extract report name and search path, format into CSV
sOutput = sOutput & Chr(34) & oAuthoredReport.defaultName.Value & Chr(34) & "," & Chr(34) & oAuthoredReport.searchPath.Value & Chr(34) & vbCrLf
End If
Set oAuthoredReport = Nothing
Next i
' write output to file
Set oTxt = oFSO.CreateTextFile(CheckPath(txtDownloadPath) & "reports_(" & txtPackageName & ").csv", True)
oTxt.Write sOutput
oTxt.Close
Set oTxt = Nothing
Screen.MousePointer = vbNormal
' notify user
MsgBox "Extract completed successfully.", vbInformation, "Complete"
Exit Sub
Exception:
' handle errors
If Err.Number = 91 Then ' report has no package
Resume Next
Else
Screen.MousePointer = vbNormal
MsgBox Err.Description, vbCritical, "Error"
End If
End Sub
Thanks for sharing your solution.
I had a similar problem to solve in Java.
I wanted to know which packages are used in the reports that are saved in the Cognos8 Content Store.
My code is still a prototype, so I only share the important parts:
First, the search path to use in the SearchPathMultipleObject class:
String reportPaths = "/content//report";
Second the properties to be able to use the metadataModelPackage:
PropEnum[] properties =
{
PropEnum.defaultName,
PropEnum.searchPath,
PropEnum.metadataModelPackage
};
Third: Go through the BaseClass objects and extract the metadataModelPackage information:
for (int i = 0; i < results.length; i++)
{
BaseClass results[] = cmService.query(p1, properties, sortBy, options);
AuthoredReport rep = (AuthoredReport)results[i];
BaseClass[] pack = rep.getMetadataModelPackage().getValue();
if (pack != null) {
for (int j = 0; j < pack.length; j++)
{
String packPath = pack[j].getSearchPath().getValue().toString();
int position = packPath.indexOf("/package");
String packName = packPath.substring(position+16, packPath.length()-2);
System.out.println(packName);
}
}
}
Regards,
Stefan