TM1API how to find out if cell is updatable?

Post Reply
SirDuke
Posts: 9
Joined: Thu May 30, 2013 8:46 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2010

TM1API how to find out if cell is updatable?

Post by SirDuke »

Hello

I'd like to render a cube slice using native C++/VB6 TM1 API. Everything seems more or less "straighforward". I can get the cell values from ViewArray (using eitherTM1ViewArrayConstruc=>TM1ViewArrayValueByRangeGet or TM1GetViewByName.
However I'm scratching my head how to find out which of these cells are updatable and which not (e.g. white or greyed in Architect/Perspectives). I tried to use TM1ValIsUpdatable however it always returns false as a result.
Also I would have to call it for every cell one by one which seems strange compared to such hi-level functions above allowing to get all cell values in one hit.

I know tm1 api is a bit boundary topic, anyhow any help would be highly appreciated :D
jrizk
Posts: 48
Joined: Thu Nov 19, 2009 10:38 pm
OLAP Product: Tm1
Version: 10.2.2
Excel Version: 2010

Re: TM1API how to find out if cell is updatable?

Post by jrizk »

Hi,

You can use the API function TM1CubeCellWriteStatusGet - ie

Declare Function TM1CubeCellWriteStatusGet Lib "tm1api.dll" (ByVal hPool As Long, ByVal hCube As Long, ByVal hArray As Long) As Long

hArray will need to be populated with the handles to each of the dimension elements for the cell\value you are testing.

TM1CubeCellWriteStatusGet itself will return an array and you will need to:
a. get the handle of index 1 of that array using TM1ValArrayGet.
b. get the value of the handle in a. above using TM1ValIndexGet.

The value TM1ValIndexGet in b. (above) returns a value of 1 to 9. Anything other than a 9 indicates the cell is NOT updateable.

So to demonstrate (assuming that the handles of the cube and cube dimensions have already been obtained):

NoParameters = NoCubeDimensions
ReDim lArray(NoParameters)
hArray = TM1ValArray(hArrayPool, lArray(), NoParameters)

hDim1El = TM1ObjectListHandleByNameGet(hPool, hDim1 , TM1DimensionElements, dim1elString)
hDim2El = TM1ObjectListHandleByNameGet(hPool, hDim2 , TM1DimensionElements, dim2elString)
etc...

TM1ValArraySet hArray, hDim1El, 1
TM1ValArraySet hArray, hDim2El, 2
etc...

hCubeCellUpdate = TM1CubeCellWriteStatusGet(hPool, cubeHandlebyName, hArray)

'Test to see if handle is a valid array (in case dimension/element handles don't exist) - otherwise could cause a crash
If TM1ValType(hUser, hCubeCellUpdate) = TM1ValTypeArray() Then bCubeCellUpdateArray = True

If bCubeCellUpdateArray = True Then
hCubeCellUpdateIndex = TM1ValArrayGet(hUser, hCubeCellUpdate, 1)
iCubeCellUpdateIndex = TM1ValIndexGet(hUser, hCubeCellUpdateIndex)
End if

'if iCubeCellUpdateIndex = 9 then Updateable otherwise NOT Updateable

You would then loop over the values you are testing and repopulate hArray in TM1CubeCellWriteStatusGet

Hope this helps.
J.Rizk
Tm1 for everyone
SirDuke
Posts: 9
Joined: Thu May 30, 2013 8:46 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2010

Re: TM1API how to find out if cell is updatable?

Post by SirDuke »

Many many thanks jrizk, I'm going to implement this.
Still curious if there is another undocumented function to give me such flag for whole viewarray though
lotsaram
MVP
Posts: 3654
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: TM1API how to find out if cell is updatable?

Post by lotsaram »

SirDuke wrote:Many many thanks jrizk, I'm going to implement this.
Still curious if there is another undocumented function to give me such flag for whole viewarray though
If you think about it a cell array could contain leaf cells and consolidated cells. As well amongst the leaves there could be numeric input cells and non-updatable rule calculated cells, ... and that's before you even consider overlaying the effects of element and cell security.

That's maybe a long way of saying that "writeable" isn't a property of an array, only of an individual cell. Although it might seem a useful shortcut to be able to retrieve true or false for a cell-writeable property of the whole array if the return value was false then you would still have to go back and loop through the array and examine each cell to see if there were some writeable cells, therefore the value of such a property would be quite limited which probably explains why it doesn't exist.
SirDuke
Posts: 9
Joined: Thu May 30, 2013 8:46 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2010

Re: TM1API how to find out if cell is updatable?

Post by SirDuke »

lotsaram wrote:...That's maybe a long way of saying that "writeable" isn't a property of an array, only of an individual cell....
By all means. I meant if there would be function to return array of flags (for each cell), likewise there is TM1ViewArrayValueByRangeGet to return array of values (for each cell) within viewarray
SirDuke
Posts: 9
Joined: Thu May 30, 2013 8:46 pm
OLAP Product: TM1
Version: 9.5.2
Excel Version: 2010

Re: TM1API how to find out if cell is updatable?

Post by SirDuke »

jrizk wrote:The value TM1ValIndexGet in b. (above) returns a value of 1 to 9. Anything other than a 9 indicates the cell is NOT updateable.
jrizk: it works like a charm, many thanks again!!!
Post Reply