Browse the Tree Structure Types and Functions

The following functions allow retrieving the parent node, children, or siblings of a given node.

getParent

Syntax

It is possible to get the parent of a specific node with given <designation>. See to the following syntax.

var result = getParent(<designation>)

var obj = new BrowserObject(<designation>);

var result = getParent(obj);

getChildren

Syntax

It is possible to get the children of a specific node with a given <designation>. See to the following syntax.

var result = getChildren(<designation>)

var obj = new BrowserObject(<designation>);

var result = getChildren(obj);

getSiblings

Syntax

It is possible to get the siblings of a specific node with a given <designation>. See to the following syntax.

var result = getSiblings(<designation>)

var obj = new BrowserObject(<designation>);

var result = getSiblings(obj);

Parameter Usage

Parameter

Type

Default

Use

Annotation

designation

String

-

Mandatory

CNS full path (designation).

Result

  • If any parent node is found that matches the designation, the getParent method returns the BrowserObjectResult that contains the BrowserObject of the parent node.
    In case a root node is indicated, a null BrowserObject is returned and an error is generated (see Error Handling below).
  • If any child node is found that matches the designation, the getChildren method returns the BrowserObjectsResult that contains the BrowserObject array of child nodes.
    In case a node has no children, an empty BrowserObject array is returned.
  • If any sibling node is found that matches the designation, the getSiblings method returns the BrowserObjectsResult t that contains the BrowserObject array of sibling nodes.
    In case the node has no sibling, an empty BrowserObject array is returned.
    In case a root node is indicated, a null BrowserObject is returned and an error is generated (see Error Handling below).
  • If any errors occurred during the browsing operation, these methods returns a BrowserObject with the error property that indicates the reason why the operation failed.

Error Handling

Errors can occur in case:

  • The getParent method is called for a root node (for example, Management View).
    • Error message: It's not possible to get the parent of a root node <Designation>.
  • The getSiblings method is called for a root node (for example, Application View).
    • Error message: It's not possible to get the siblings of a root node <Designation>.
  • <designation> does not exist.
    • Error message: Node not found <Designation>
  • invalid data type for parent node, child nodes, or sibling nodes:
    • Error messages:
      - The input for getParent must be a BrowserObject or a string.
      - The input for getChildren must be a BrowserObject or a string.
      - The input for getSiblings must be a BrowserObject or a string.

Examples

 

How to get the parent of the Logics node

var browserObject = new BrowserObject("System1.ApplicationView:ApplicationView.Logics");

    var parent = getParent(browserObject)

if (!parent.error)

    console("Parent = {0}", parent.browserObject)

 

How to get the children of the Logics node

var browserObject = new BrowserObject("System1.ApplicationView:ApplicationView.Logics");

var children = getChildren(browserObject)

if (!children.error)

{

    console("Children Count = {0}", children.browserObjects.length)

    console("Children = {0}", children.browserObjects)

}

 

How to get the parent of the Field Networks node

var parent = getParent("System1.ManagementView:ManagementView.FieldNetworks")

if (!parent.error)

    console("Parent = {0}", parent.browserObject)

 

How to get the children of the Management View node

var children = getChildren("System1.ManagementView:ManagementView")

if (!children.error)

{

    console("Children Count = {0}", children.browserObjects.length)

    console("Children = {0}", children.browserObjects)

}

 

How to get siblings of the Scripts node

var browserObject = new BrowserObject("System1.ApplicationView:ApplicationView.Logics.Scripts");

    var siblings = getSiblings(browserObject)

if (!siblings.error)

{

    console("Siblings Count = {0}", siblings.browserObjects.length)

    console("Siblings = {0}", siblings.browserObjects)

}