cubewise-code / tm1py

TM1py is a Python package that wraps the TM1 REST API in a simple to use library.
http://tm1py.readthedocs.io/en/latest/
MIT License
187 stars 107 forks source link

Call of "get_all_leaf_element_identifiers" #1067

Closed TM1si closed 6 months ago

TM1si commented 6 months ago

I try checking valid element names in a cell definition. I found some API-functions in the documentation, but was not able to call it, bc. it is unknown while code is executed. I nearly imported everything I found:

from TM1py import TM1Service, Subset, DimensionService, ElementService
from TM1py import GitService, HierarchyService, MonitoringService, PowerBiService, ProcessService, RestService, SandboxService, SecurityService, ServerService, SubsetService, TM1Service, ViewService, Annotation, Application, Chore, ChoreFrequency, ChoreStartTime, ChoreTask, Cube, Dimension, Element, ElementAttribute, Git

But function "get_all_leaf_element_identifiers" remains still unknown. I also did not get the proper syntax, i think. Actually that's my code for getting all leaf and consolidated elements for later checking against cells:

AnalyzeCells(tm1, cubeName, srcCells ):
    cube = tm1.cubes.get(cubeName)  # cubename for further data
    dimensions = cube.dimensions
    dimensionsCount = len(cube.dimensions)
    NElements = []
    CElements = []

    for index in range(dimensionsCount):   # index 0 ... n-1
        dimName = dimensions[index]
        leafElements = tm1.get_all_leaf_element_identifiers(dimension_name = dimName, hierarchy_name = '')
        NElements.append(leafElements)
        consolElements = tm1.get_consolidated_element_names(dimension_name =  dimName, hierarchy_name = '')
        CElements.append(consolElements)

Any idea or hint for example code?

rclapp commented 6 months ago

Hi @TM1si you don't need to import those names as all of the services (except manager) are exposed through the TM1Service. The same way you get the cube, you would also call this function

# assuming you have a live connection to TM1 named tm1
leafElements = tm1.elements.get_all_leaf_element_identifiers(...)
TM1si commented 6 months ago

OK, I removed all the unneeded services, but I still get an error on this line: leafElements = tm1.elements.get_all_leaf_element_identifiers(dimName, hierarchy_name = '') ERROR: Text: '{"error":{"code":"501","message":"Syntax error at or near: ' } , 0 ) }', character position 65"}}' - Status Code: 400 - Reason: 'Bad Request' - Headers: {'Content-Length': '108', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json; charset=utf-8', 'OData-Version': '4.0'}

If I fix the dimension name to "Monat", then I get: ERROR: Text: '{"error":{"code":"501","message":"Syntax error at or near: ' } , 0 ) } } ON ROWS, \n { [} ... ', character position 84"}}' - Status Code: 400 - Reason: 'Bad Request' - Headers: {'Content-Length': '131', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json; charset=utf-8', 'OData-Version': '4.0'}

rclapp commented 6 months ago

You can’t pass a blank string as a hierarchy, just leave it blank or pass the dimension name twice if you don’t have a hierarchy

From: TM1si @.> Reply-To: cubewise-code/tm1py @.> Date: Wednesday, March 6, 2024 at 9:33 AM To: cubewise-code/tm1py @.> Cc: "Clapp, Ryan" @.>, Comment @.***> Subject: Re: [cubewise-code/tm1py] Call of "get_all_leaf_element_identifiers" (Issue #1067)

OK, I removed all the unneeded services, but I still get an error on this line: leafElements = tm1.elements.get_all_leaf_element_identifiers(dimName, hierarchy_name = '') ERROR: Text: '{"error":{"code":"501","message":"Syntax error at or near: ' } , 0 ) }', character position 65"}}' - Status Code: 400 - Reason: 'Bad Request' - Headers: {'Content-Length': '108', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json; charset=utf-8', 'OData-Version': '4.0'}

If I fix the dimension name to "Monat", then I get: ERROR: Text: '{"error":{"code":"501","message":"Syntax error at or near: ' } , 0 ) } } ON ROWS, \n { [} ... ', character position 84"}}' - Status Code: 400 - Reason: 'Bad Request' - Headers: {'Content-Length': '131', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json; charset=utf-8', 'OData-Version': '4.0'}

— Reply to this email directly, view it on GitHubhttps://github.com/cubewise-code/tm1py/issues/1067#issuecomment-1981004005, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEK7GZTK5XGHQCNLK7ADTJLYW4SJ7AVCNFSM6AAAAABEHKRTG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBRGAYDIMBQGU. You are receiving this because you commented.Message ID: @.***>

TM1si commented 6 months ago

Hooray! That's it! Thanks a lot.