If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Simple SDK shortcut problem

Started by jluckhoff, 03 Aug 2017 02:03:19 AM

Previous topic - Next topic

jluckhoff

Morning all,

I am stuck with what is probably a very simple issue.

I am using the SDK to move a few reports to a central Folder and replace their entries with a shortcut pointing to the new Location.

I can manage to pick up the reports and move them, however when I create teh shortcut I simply cannot seem to set the target path.

Unfortunatlely the web and cognos documentation are scarce on examples of creating a shortcut and I was hoping that one of cou could help

My code is in VB and roughtly Looks like this:


        Dim bc As baseClass() = cBICMS.query(reportsPath, props, s, qo)

        If bc.Length > 0 Then
            For Each report_item As baseClass In bc
                If report_item.defaultName.value = "A_usernametest" Then
                    Response.Write(report_item.defaultName.value)
                    Response.Write("Moving report")

                    Dim rReport As New report()

                    Dim reportToMove As New stringProp()
                    reportToMove.value = report_item.searchPath.value
                    rReport.searchPath = reportToMove
                    Dim bcaMove As baseClass() = {rReport}
                    Dim cpOptions As New moveOptions()

                    Dim cmTargetPath As New searchPathSingleObject()
                    cmTargetPath.Value = "/content/folder[@name='Reports']/folder[@name='TEST']"


                    'move it
                    Dim bcaMoveResults As baseClass() = cBICMS.move(bcaMove, cmTargetPath, cpOptions)

                    Response.Write("Report Moved To " & cmTargetPath.Value)

' now the shortcut part where I am stuck:


                    Dim sc As New cognosdotnet_10_2.shortcut
                    Dim defaultname As New tokenProp
                    defaultname.value = "test"
                    sc.defaultName = defaultname



                    'Set the target of the shorcut
                    ' cant figure this one out just yet, something to do with using a Baseclassarrayprop, but I cannot seem to add values to the array
                    'also grabbing the new searchpath location of the moved report is giving me trouble
                    Dim Target As New stringProp
'......

                    'the following line creates the shortcut in the expected location with the correct name, however the link is broken

                    Dim scadd As baseClass() = {sc}




Any help, comments (critizism) will be much appreciated.

Thanks

jluckhoff

Hi,

Thought I'd post a follow up on this Topic.

Essentially I did not get it to work but found a way around it by using the code I had working to create a shortcut item with the correct Name and in the right Location after moving the Report.

THis was done as follows:

  Dim userNamespace As String = ""

        'Dim cognos_bais As New agentService
        Dim cBICMS As New contentManagerService1
        Dim credentialXML As New System.Text.StringBuilder

        cBICMS.Url = "http://cognosservername:9300/p2pd/servlet/dispatch/ext"
        'Response.Write(cBICMS.Url.ToString())


        credentialXML.AppendFormat("<credential>")
        credentialXML.AppendFormat("<namespace>{0}</namespace>", "Default Namespace Name ")
        credentialXML.AppendFormat("<username>{0}</username>", "ADMIN")
        credentialXML.AppendFormat("<password>{0}</password>", "+++your Password+++++")
        credentialXML.Append("</credential>")

        Dim encodedCredentials As String = credentialXML.ToString()
        Dim xmlEncodedCredentials As New xmlEncodedXML

        xmlEncodedCredentials.Value = encodedCredentials

        Dim emptyRoleSearchPathList As New searchPathSingleObject

        Try
            cBICMS.logon(xmlEncodedCredentials, Nothing)
        Catch ex As Exception
            Response.Write(ex.ToString)
            Response.Write(xmlEncodedCredentials.ToString())
        End Try

        Dim rootSearchPath = New searchPathMultipleObject
        rootSearchPath.Value = "~"

        Dim bi As New biBusHeader

        Dim resultMessage As String

        If cBICMS Is Nothing Then
            resultMessage = "the Server connection provided is invalid."
            Response.Write(resultMessage)
        End If
        Dim props As propEnum() = New propEnum() {propEnum.searchPath, propEnum.defaultName, propEnum.disabled, propEnum.defaultDescription, propEnum.target, propEnum.targetOptions, propEnum.targetParameters, propEnum.parent, propEnum.storeID}
        Dim s As sort() = New sort() {New sort()}
        s(0).order = orderEnum.ascending
        s(0).propName = propEnum.defaultName
        Dim qo As New queryOptions()

        Dim output As New StringBuilder()

        ' Look for all of the reports.
        output.AppendFormat(vbLf & "Reports:" & vbLf)

        Dim reportsPath As New searchPathMultipleObject()
        reportsPath.Value = "/content//report"    ' shortcut, report, schedule

        Dim bc As baseClass() = cBICMS.query(reportsPath, props, s, qo)



        If bc.Length > 0 Then
            For Each report_item As baseClass In bc
                If report_item.defaultName.value = "A_usernametest" Then 'A_usernametest
                    Response.Write(report_item.defaultName.value)
                    Response.Write("Moving report")

                    Dim rReport As New report()

                    Dim reportToMove As New stringProp()
                    reportToMove.value = report_item.searchPath.value
                    rReport.searchPath = reportToMove
                    Dim bcaMove As baseClass() = {rReport}
                    Dim cpOptions As New moveOptions()

                    Dim cmTargetPath As New searchPathSingleObject()
                    'cmTargetPath.Value = "/content/folder[@name='Reports']/folder[@name='TEST']"
                    cmTargetPath.Value = "/content/folder[@name='Reports']"

                    Dim cmSourcePath As New searchPathSingleObject()
                    cmSourcePath.Value = report_item.parent.value(0).searchPath.value


                    'move it
                    Dim bcaMoveResults As baseClass() = cBICMS.move(bcaMove, cmTargetPath, cpOptions)

                    Response.Write("Report Moved To " & cmTargetPath.Value)

                    ' create a new shortcut

                    Dim sc As New cognosdotnet_10_2.shortcut
                    Dim defaultname As New tokenProp
                    defaultname.value = "testABV"
                    sc.defaultName = defaultname

                    Dim scadd As baseClass() = {sc}

                    'Create the shortcut
                    Dim result As baseClass() = cBICMS.add(cmSourcePath, scadd, Nothing)


This creates a broken shortcut in cognos i.e. a shortcut witout a target link, but a shortcut nontheless

Next I hacked the System by simply updating the shorcut's target path in the respository table called CMOBJPROPS6 :)

To do this in .net you ened to grab the STOREID property of the newly created shortuct and use it to fetch ist CMID, once you have the CMID ist pretty straightforward:

So to get the CMID I used the following code to generate the SQL which is then passed to an Oracledataclient object and executed:



                   Dim storeid As String
                    storeid = result(0).storeID.value.Value
                    'because I am not smart enough go set the shortcut target we do it in the database:

                    'connect to the content store

                    'set the sql to fetch the newly created storeid



                    strsql = "SELECT DISTINCT CMID FROM FUM_C1022CS2.CMSTOREIDS WHERE LOWER(STOREID) = LOWER('" & storeid & "')"

                   
                   
                   dim var_CMID as string
                   
                    CMID = 'execute the oracle Reader using your Oracledataclient datareader

                    Dim targetpath As String = bcaMoveResults(0).searchPath.value

'Format so SQL can cope with single quotes
                    targetpath = targetpath.Replace("'", "''")

now Format your update sql
                    strsql = "UPDATE FUM_C1022CS2.CMOBJPROPS6  SET TARGET = '" & targetpath & "' WHERE CMID = " & CMID

' And execute in your database!



That worked fine for me and I was able to move a few reports and leave a shortcut in their original Location.

Obviously you should never update the contentstore with SQL as I did, but as I could not figure out the shortcut object in SDK and did not have hours to waste for something I wnated to do once off, this worked fine.

Just back up your contentstore before you do this :)

If anyone does know how to update the shortcut locaiton using the SDK. Please be kind and share .