Bug in the .NET API when retrieving elements for TM1Cell?
Posted: Tue Oct 13, 2009 4:47 pm
I have to familiarize myself with the TM1 .NET API for work and either I have come across a bug in the API or am doing something completely wrong.
When trying to read a cell value from a cube the API help file says you just have to pass an array of strings that make up the dimensionality of the cell you want to retrieve the value for. This works fine when every dimension in the cube is a flat dimension. However, whenever I use a dimension that has consolidated elements the API can only see those elements that are root elements.
Here is my code, which is pretty much lifted directly from their help files. Note that the _tm1server object is correctly instantiated. The user I'm using is an admin so it should be able to see everything as well:
public void TM1CubeReadWriteCellNoView()
{
string[] elements = { "Actuals", "June" };
TM1Cell cell;
try
{
cell =_tm1server.Cubes["Test2"].Cells[elements];
Console.WriteLine("Current value for cube cell: " + cell.Value);
Console.WriteLine("Adding 3 to the current cell value");
cell.Value = ((double)cell.Value + 3.0);
cell.Refresh();
Console.WriteLine("New value for cube cell: " + cell.Value);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
This will work fine if "Actuals" and "June" are root elements. But let's say for instance I add "Quarter 2" as a parent of "June" in the second dimension I will get the following error: Element [June] not found in dimension [Year]. If I then switch the second element of the string array from "June" to "Quarter 2" it will work fine.
I believe what is happening is that when the API goes to verify the elements you pass it are valid elements for the Dimension it is using the "Elements" or "RootElements" property (both return only the root elements of dimension) instead of AllElements. Does anyone have any experience with this? Am I missing something completely obvious or is my hunch right?
This is on Windows XP and TM1 9.4.1 MR1
When trying to read a cell value from a cube the API help file says you just have to pass an array of strings that make up the dimensionality of the cell you want to retrieve the value for. This works fine when every dimension in the cube is a flat dimension. However, whenever I use a dimension that has consolidated elements the API can only see those elements that are root elements.
Here is my code, which is pretty much lifted directly from their help files. Note that the _tm1server object is correctly instantiated. The user I'm using is an admin so it should be able to see everything as well:
public void TM1CubeReadWriteCellNoView()
{
string[] elements = { "Actuals", "June" };
TM1Cell cell;
try
{
cell =_tm1server.Cubes["Test2"].Cells[elements];
Console.WriteLine("Current value for cube cell: " + cell.Value);
Console.WriteLine("Adding 3 to the current cell value");
cell.Value = ((double)cell.Value + 3.0);
cell.Refresh();
Console.WriteLine("New value for cube cell: " + cell.Value);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
This will work fine if "Actuals" and "June" are root elements. But let's say for instance I add "Quarter 2" as a parent of "June" in the second dimension I will get the following error: Element [June] not found in dimension [Year]. If I then switch the second element of the string array from "June" to "Quarter 2" it will work fine.
I believe what is happening is that when the API goes to verify the elements you pass it are valid elements for the Dimension it is using the "Elements" or "RootElements" property (both return only the root elements of dimension) instead of AllElements. Does anyone have any experience with this? Am I missing something completely obvious or is my hunch right?
This is on Windows XP and TM1 9.4.1 MR1