Page 1 of 1
Java API com.applix.tm1.TM1Val@1a93a0d8
Posted: Mon Sep 26, 2011 7:05 am
by maps
Hello Everyone,
I'm trying to get familiar with the java api but I got some starting problems. Here is the code I wrote:
Code: Select all
...
final String TM1SERVERNAME = "DevSystem";
TM1Bean bean = new TM1Bean();
bean.setAdminHost(".....");
System.out.println("Nr. of Servers: " + bean.getNumberOfServers());
TM1Server server = bean.openConnection(TM1SERVERNAME, "myusername", "mypassword");
System.out.println("Clientname: " + server.getClientName());
TM1Dimension tm1d = server.getDimension("Kat4");
System.out.println("number of El: " + tm1d.getElementCount());
TM1Dimension tm1d2 = server.getDimension(5);
System.out.println("number of El:" + tm1d2.getElementCount());
bean.closeConnection(server);
Output of the printlns is:
Code: Select all
Nr. of Servers: 2
Clientname: com.applix.tm1.TM1Val@1a93a0d8
number of El: com.applix.tm1.TM1Val@5224d289
number of El: com.applix.tm1.TM1Val@6f7a4a80
The connection seems to be established because it finds all the servers (2).
But when I'm trying to access the objects and use the methods I'm getting the output u see above. "com.applix.tm1...."
What did I forget to do? Any ideas?
Re: Java API com.applix.tm1.TM1Val@1a93a0d8
Posted: Mon Sep 26, 2011 6:46 pm
by csjean
Hi,
The problem is that the methods you use (getClientName, getElementCount, etc)
do not return string or ints
but returns a TM1 "value wrapper class" called TM1Val.
Almost all TM1 method that return something, returns a TM1Val class object
(that is what you see here -> you are actualy trying to print the class itself).
So, for what you want to do to work, you can try this:
Code: Select all
System.out.println("Nr. of Servers: " + bean.getNumberOfServers());
TM1Server server = bean.openConnection(TM1SERVERNAME, TM1USER, TM1PWD);
System.out.println("Clientname: " + server.getClientName().getString());
TM1Dimension tm1d = server.getDimension("Kat4");
System.out.println("number of El: " + tm1d.getElementCount().getInt());
TM1Dimension tm1d2 = server.getDimension(5);
System.out.println("number of El:" + tm1d2.getElementCount().getInt());
bean.closeConnection(server);
You can checkout the javadoc in <TM1 install dir>\API\JavaDoc
Hope this helps.
Re: Java API com.applix.tm1.TM1Val@1a93a0d8
Posted: Tue Sep 27, 2011 6:23 am
by maps
My mistake. Of course I read the API, but I did'nt notice that. Thanks a lot.
Next time they should implement the toSting method in an informative way
@csjean
Are you familiar with using the java api? Do you know a source where I can get some programing examples? In the documentation of the api I can only find 4 examples and for me using the api is not that intuitive...
Especially information how to work with hierarchies would be helpful, because I don't know how to start...
Re: Java API com.applix.tm1.TM1Val@1a93a0d8
Posted: Tue Sep 27, 2011 1:35 pm
by csjean
Hi maps,
maps wrote:My mistake. Of course I read the API, but I did'nt notice that. Thanks a lot.
Next time they should implement the toSting method in an informative way
Oh Yesss! I very much agree.
maps wrote:
@csjean
Are you familiar with using the java api? Do you know a source where I can get some programing examples? In the documentation of the api I can only find 4 examples and for me using the api is not that intuitive...
Especially information how to work with hierarchies would be helpful, because I don't know how to start...
Unfortunately I'm not that familliar with using the API. I've tinkered a bit with it but that's it.
As for programming examples, I haven't found much...
I also agree with you that it's not that intuitive and not well documented (which is not a good combination IMHO).
For the working with hierarchies, can you be more precice about what you want to do?
Re: Java API com.applix.tm1.TM1Val@1a93a0d8
Posted: Wed Sep 28, 2011 8:08 am
by maps
Two things I'm struggeling with at the moment.
Hierarchy: Just want to walk through a hierarchy starting with an consolidated element. But I don't know how to start. Can't find a method to access an Instance of TM1Hierarchy (or level, member...). I've been looking in the methods of Server, Elements, Dimension. I just don't know how to start.
Dimension: I like to add a new Element to an existing Dimension. Should be pretty basic, especially because how to create a new dim and insert an element is explained in the examples. Creating a new Dimension and insert new elements and save this new dimension works perfectly like in the example.
Code: Select all
TM1Dimension testDim = server.createDimension();
testDim.insertElement(TM1Element.NullElement, "oh Im a new Element", TM1ObjectType.ElementConsolidated);
testDim.register(server, "Dimension Name");
But how can I add an new Element to an existing Dimension!
I tried it in the following ways.. Without success.
Code: Select all
//1.)
TM1Dimension testDim = server.getDimension("Dimension Name");
testDim.insertElement(TM1Element.NullElement, "oh Im a new Element", TM1ObjectType.ElementConsolidated);
testDim.updateDimension(testDim);
//or optionaly in addition with the register statement.
//2.)
TM1Dimension testDim = server.getDimension("Dimension Name");
testDim.insertElement(TM1Element.NullElement, "oh Im a new Element", TM1ObjectType.ElementConsolidated);
testDim.register(server, "Dimension Name");
Re: Java API com.applix.tm1.TM1Val@1a93a0d8
Posted: Wed Sep 28, 2011 4:01 pm
by csjean
Hi maps,
Here is my code that works.
The problem is that, you cant insert an element in a registered dimension.
You have to:
- Duplicate an existing dimension
- Work on the duplicated dimension (add elements and components)
- Check the duplicated dimension
- Update the original with the new
The following code works.
There's a lot of extra stuff so you can follow what happens.
Code: Select all
TM1Dimension testDim = server.createDimension();
if (testDim.isError()) {
System.out.println( "CREATE DIM Error message:" + testDim.getErrorMessage());
} else {
bool = testDim.insertElement(TM1Element.NullElement, "oh Im a new Element", TM1ObjectType.ElementSimple);
System.out.println( "INSERT Error message:" + bool.getErrorMessage());
bool = testDim.check();
System.out.println( "CHECK Error message:" + bool.getErrorMessage());
bool = testDim.register(server, "ZZZZ_CSJ_TEST_DIM");
System.out.println( "REGISTER Error message:" + bool.getErrorMessage());
}
testDim = server.getDimension("ZZZZ_CSJ_TEST_DIM");
System.out.println( "GET DIMENSION Error message:" + testDim.getErrorMessage());
TM1Dimension testDim2 = testDim.duplicate();
System.out.println( "GET DIMENSION Error message:" + testDim2.getErrorMessage());
TM1Element econso = testDim2.insertElement(TM1Element.NullElement, "oh Im a new Element 2", TM1ObjectType.ElementConsolidated);
System.out.println( "INSERT2 Error message:" + econso.getErrorMessage());
TM1Element echild = testDim2.insertElement(TM1Element.NullElement, "oh Im a new CHILD OF Element 2", TM1ObjectType.ElementSimple);
System.out.println( "INSERT3 Error message:" + echild.getErrorMessage());
/** Add Consolidation **/
double f_tmp = Double.valueOf(1).doubleValue();
econso = testDim2.getElement("oh Im a new Element 2");
System.out.println( "getElement CONSO Error message:" + econso.getErrorMessage());
echild = testDim2.getElement("oh Im a new CHILD OF Element 2");
System.out.println( "getELEMENT CHILD Error message:" + echild.getErrorMessage());
bool = econso.addComponent(echild, new TM1Val(f_tmp));
System.out.println( "ADD COMPONENT Error message:" + bool.getErrorMessage());
bool = testDim2.check();
System.out.println( "CHECK2 Error message:" + bool.getErrorMessage());
bool = testDim.updateDimension(testDim2);
System.out.println( "UPDATE Error message:" + bool.getErrorMessage());
bean.closeConnection(server);
Hope this helps.
Re: Java API com.applix.tm1.TM1Val@1a93a0d8
Posted: Wed Aug 28, 2013 3:47 am
by daniel.pinto
Hi i'm new to TM1,I'm trying to read a cube with two dimension below example i can read the cube values.
TM1Val elemTitles = TM1Val.makeArrayVal (2);
TM1Element elerow;
TM1Element elecol ;
elerow = oCube.getDimension(0).getElement(1);
elemTitles.addToArray(elerow);
elecol =oCube.getDimension(1).getElement(1);
elemTitles.addToArray(elecol);
oCube.getCellValue (elemTitles);
I'm trying to read the view on a cube . The cube can have more than 2 dimensions. no been successful,If anybody can post some samples it would be really helpful.