GetBlob API function -- API experts, please help!

Post Reply
User avatar
Harvey
Community Contributor
Posts: 236
Joined: Mon Aug 04, 2008 4:43 am
OLAP Product: PA, TM1, CX, Palo
Version: TM1 8.3 onwards
Excel Version: 2003 onwards
Contact:

GetBlob API function -- API experts, please help!

Post by Harvey »

Hi all,

I've always found it frustrating that I have to use unattractive, inflexible action buttons to link to reports that have been uploaded to the TM1 Applications folder.

Hence, I'm attempting to develop a solution that will do this from regular hyperlinks in Excel. I've got the technology in place, but can't seem to work out the API code to call GetBlob in VB.NET.

Part 2 of my problem is that I don't know how to link the Applications folder path (eg, Finance/P&L.xls) to the Blob name in TM1 (eg P&L.xls_20080627091213.xls).

When I'm done I'll happily post the solution to the forum for all to share.

My code follows the post. Thanks in advance for any advice.
Harvey.

Here's the code. Note that some functions are omitted for brevity, but have been used in many other functions and are working correctly.

Code: Select all

Public Declare Function TM1BlobGet Lib "tm1api.dll" (ByVal hUser As Integer, ByVal hBlob As Integer, ByVal x As Integer, ByVal n As Integer, ByVal buf As String) As Integer
' Note: I have tried StringBuilder instead of String above and still get the same error

Public Function BlobGetData(ByVal hUser As Integer, ByVal strServerName As String, ByVal strBlobName As String, ByVal intBlobOffset As Integer, ByVal intMaxBytes As Integer) As String
            Dim hPool As Integer
            Dim hHandle As Integer
            Dim hBlobName As Integer
            Dim hBlob As Integer
            Dim hObject As Integer
            Dim hReturn As Integer
            Dim strBuffer As String

            Try
                hPool = GetPoolHandle() 
                hHandle = GetServerHandle(hPool, hUser, strServerName) 

                hBlobName = TM1ValString(hPool, strBlobName, 250)
                If CheckForAPIError(hUser, hBlobName) <> 0 Then Exit Try 

                hBlob = TM1ObjectListHandleByNameGet(hPool, hHandle, TM1ServerBlobs(), hBlobName)
                If CheckForAPIError(hUser, hBlob) <> 0 Then Exit Try

                hReturn = TM1BlobOpen(hPool, hBlob)
                If TM1ValBoolGet(hUser, hReturn) <> 1 Then
                    _ErrorString = "Could not open the blob"
                    Exit Try
                End If

                TM1BlobGet(hUser, hBlob, intBlobOffset, intMaxBytes, strBuffer)
                ' *** Note: The above function call fails with a NullReferenceException and no further information

                hReturn = TM1BlobClose(hPool, hBlob)

                If TM1ValBoolGet(hUser, hReturn) <> 1 Then
                    _ErrorString = "Could not close the blob"
                    Exit Try
                End If

            Catch ex As Exception
                _ErrorString += vbCrLf & "Error in BlobGetData: " & ex.ToString
            Finally
                If hPool <> 0 Then TM1ValPoolDestroy(hPool)
            End Try

            Return strBuffer
        End Function
Take your TM1 experience to the next level - TM1Innovators.net
User avatar
Harvey
Community Contributor
Posts: 236
Joined: Mon Aug 04, 2008 4:43 am
OLAP Product: PA, TM1, CX, Palo
Version: TM1 8.3 onwards
Excel Version: 2003 onwards
Contact:

Re: GetBlob API function -- API experts, please help!

Post by Harvey »

Just a quick update to save anyone from wasting time trying to solve the first part. I've now got the blob/xls file coming back from the API successfully (it needed to be a byte [] in the API function declaration instead of the string suggested in the API documentation -- .NET was automatically converting some of the data to equivalent unicode characters, essentially corrupting the file).

Now, for part 2, I need to work out how to take an TM1 Application display path (like Reports/Finance/P&L.xls) and map that to the resulting blob name on the server (like P&L.xls_20080804060618.xls). I can see that the }ApplicationEntries dimension has the path information and that the .blob file it points to contains the name I want, but I don't know the API function to retrieve this information from TM1.

Any ideas would be welcome.

Cheers,
Harvey.
Take your TM1 experience to the next level - TM1Innovators.net
User avatar
Alan Kirk
Site Admin
Posts: 6606
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: GetBlob API function -- API experts, please help!

Post by Alan Kirk »

Lazarus wrote:Any ideas would be welcome.
Don't despair at the lack of response (to date) on this one; I don't think that a lot of people are working with the API in .Net yet. I know it's something that I'll need to do in due course (even though I am no fan of .Net and want to hold on to VB Classic for as long as possible), but the chances are that you're "trail blazing" a bit at the moment.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Post Reply