Querying point hierarchy list from global script
-
Hi,
I was wondering if there is a function available for querying the point hierarchy from a global script, similar to DataPointQuery?
Also, are there any docs regarding the functions/methods that are available in the global scripts, like DataPointQuery?
Thanks
Ian -
Hi Ian,
All the functions that would be available in other scripting environments would be available in the global script environment. For instance
var rootFolders = JSON.parse( JsonEmport.getConfiguration("pointHierarchy") )["pointHierarchy"]; print( rootFolders );
which will export the hierarchy, then parse it into a javascript object. You could manipulate that however you wanted.and reimport with
JsonEmport.doImport( {"pointHierarchy": rootFolders } );
Methods available to JavaScript are most definitively found here: https://github.com/infiniteautomation/ma-core-public/blob/main/Core/web/WEB-INF/dox/mangoJavaScript.htm
Alternatively you could get the PointHierarchy right from the code, then you could use its methods. Like,
function printContextPointPath( cxtPnt ) { print( com.serotonin.m2m2.vo.hierarchy.PointHierarchy.getPath( cxtPnt.getDataPointWrapper().getId(), com.serotonin.m2m2.db.dao.DataPointDao.instance.getPointHierarchy( true ).getRoot() ) ); //# use getPointHierarchy( false ) if you're going to modify it and call the DPD's savePointHierarchy method. } printContextPointPath(p);
Methods in point hierarchies and point folders are in these classes: https://github.com/infiniteautomation/ma-core-public/tree/main/Core/src/com/serotonin/m2m2/vo/hierarchy
-
Great thanks! I will try that out.