NestedIntervalUtils - Global

The NestedIntervalUtils class provides methods for managing the planned task tree structure for the planned task [planned_task] table.

This API requires that the planned_task table has integer fields called a11, a12, a21, a22, level, and child_position. The table must also have three reference fields called parent, root_id, and top_task.

Use these methods to manage the tree structure for the planned_task table in the services interface.

NestedIntervalUtils - changeParent(GlideRecord node, String newParentID)

Changes the parent of the given node to the record identified by the sys_id specified in the newParentID parameter, and recalculates the tree values for the record and all of its descendants.

Table 1. Parameters
Name Type Description
node GlideRecord Record of the node whose parent is to be changed
newParentID String sys_id of the new parent for the record
Table 2. Returns
Type Description
Number Status:
  • 1 = success
  • 2 = duplicate (relationship already exists)
  • 3 = recursive
  • 4 = invalid data
  • -1 = database error

NestedIntervalUtils - checkNewParentValidity(String itemTaskSysId, String newParentSysId)

Checks the validity of a new parent node.

Table 3. Parameters
Name Type Description
itemTaskSysId String Item task sys_id
newParentSysId String sys_id of the new parent
Table 4. Returns
Type Description
Integer 1 = valid, any other value = invalid

NestedIntervalUtils - closeWholeProject(Object topTaskNode, Object taskKeyVals)

Closes all the tasks for a given root.

Table 5. Parameters
Name Type Description
topTaskNode Object sys_id of the top task or root of the project. It is the responsibility of the caller to obtain the top task of a project and pass it in the call.
taskKeyVals Object Key/value pairs to be set for each task under the project.
Table 6. Returns
Type Description
Integer Maximum level value

Use in a business rule that is expecting to close all the tasks for a project

var tree = new SNC.NestedIntervalUtilities("planned_task");
var taskKeyVals = new Object();
var nowTime = gs.nowDateTime();
var taskKeyVals = {state:"3", work_end:nowTime};
tree.closeWholeProject(current, taskKeyVals);

NestedIntervalUtils - copyPartialProject(GlideRecord node, String newParentID, Boolean isSubTree, Object resetFieldsObj, Object setDefaultsObj)

Copies a complete or partial project. The given node and all of its descendants are copied and inserted under the specified parent. It can also set default field values and reset or remove specified fields.

Table 7. Parameters
Name Type Description
node GlideRecord Record of the node to be copied
newParentID String sys_id of the parent node to insert the node under
isSubTree Boolean Indicator for whether the new tree is a subtree
resetFieldsObj Object String list of field names that need to be reset or removed
setDefaultsObj Object Hash map of field names and their default values that need to be set
Table 8. Returns
Type Description
String sys_id of the inserted top node

NestedIntervalUtils - copyPartialTree(GlideRecord node, String newParentID, Boolean isSubTree)

Copies a complete or partial tree and inserts the given node, and all of its descendants, under the specified new parent. Any subtrees within the descendants are copied over as a subtree.

Table 9. Parameters
Name Type Description
node GlideRecord Record of the node to be copied
newParentID String sys_id of the parent node under which to insert the node
isSubTree Boolean Indicator for whether the new tree is a subtree
Table 10. Returns
Type Description
String sys_id of the inserted top node

NestedIntervalUtils - deleteSubTree(GlideRecord parentNode, Boolean inclusive)

Deletes a record and all of its descendants.

Table 11. Parameters
Name Type Description
parentNode GlideRecord Node whose descendants are being deleted
inclusive Boolean Indicator for whether the passed record should also be deleted
Table 12. Returns
Type Description
void

NestedIntervalUtils - getAncestors(GlideRecord node, Boolean inclusive)

Returns all the ancestors of the given node.

Table 13. Parameters
Name Type Description
node GlideRecord Node whose ancestors are to be retrieved
inclusive Boolean Indicator for whether the passed node should be included in the returned records
Table 14. Returns
Type Description
GlideRecord Ancestors of the specified node; ordered by level ascending the tree

NestedIntervalUtils - getChildCount(String parentID)

Returns the number of child nodes for a given parent.

Table 15. Parameters
Name Type Description
parentID String Node whose child count is to be retrieved
Table 16. Returns
Type Description
Number Number of child nodes

NestedIntervalUtils - getChildren(Object parentID)

Returns all the children of a given parent; ordered by child position.

Table 17. Parameters
Name Type Description
parentID Object Record whose children are to be retrieved
Table 18. Returns
Type Description
GlideRecord All of the children in order of child position [child_position]

NestedIntervalUtils - getDescendants(GlideRecord node, Boolean inclusive, String extraQuery)

Returns all of the descendants for the given node. Records are returned in order of rows descending the tree, then by parent, and then by child position.

Table 19. Parameters
Name Type Description
node GlideRecord Node whose descendants are to be retrieved
inclusive Boolean Indicator for whether the specified node should be included in the returned records
extraQuery String Encoded query to further restrict the results of the function (similar to GlideRecord addEncodedQuery())
Table 20. Returns
Type Description
GlideRecord Ordered record of all the descendants; starting with the root and descending

NestedIntervalUtils - getDescendantsByLevel(GlideRecord node, Boolean inclusive, Number level)

Returns all of the descendants of a given node by the specified level.

Table 21. Parameters
Name Type Description
node GlideRecord Node whose descendants are to be retrieved
inclusive Boolean Indicator for whether the passed node should be included in the returned records
level Number Level of descendants to return
Table 22. Returns
Type Description
GlideRecord Ordered record of all the descendants at the specified level; starting with the root and descending

NestedIntervalUtils - getLeafNodesForStateChange(String itemTaskSysId, Boolean leafOfSuccessors)

Returns the sys_ids of nodes that need to be activated.

If the leafOfSuccessors parameter is set to true, this method first finds all active successors whose lag time is 0. From this subset of successors, it then gets the sys_ids of successors with:
  • The time constraint ASAP
  • No predecessor
  • All predecessors in the INACTIVE state
Table 23. Parameters
Name Type Description
itemTaskSysId String sys_id of the task
leafOfSuccessors Boolean If true, returns the sys_ids of all of the successor nodes of the itemTaskSysId that need to be activated. If false, returns the sys_ids of the itemTaskSysId that need to be activated.
Table 24. Returns
Type Description
String sys_ids of the nodes that need to be activated

NestedIntervalUtils - getMaxLevel(String parentID)

Returns the maximum level of the descendants of the given record.

Table 25. Parameters
Name Type Description
parentID String Record whose children's maximum levels are to be returned
Table 26. Returns
Type Description
Number Maximum level value

NestedIntervalUtils - getNewID(String oldID)

Returns the new sys_id of the record that was created by copyPartialProject() with the specified sys_id.

Table 27. Parameters
Name Type Description
oldID String sys_id of the original record
Table 28. Returns
Type Description
String New sys_id that corresponds to the new record

NestedIntervalUtils - getOldIDs()

Returns an array of the old sys_ids of the records that were copied by the most recent copyPartialTree() call.

Table 29. Parameters
Name Type Description
None
Table 30. Returns
Type Description
Array Array of strings that contains the old sys_ids of the copied records

NestedIntervalUtils - getSiblings(GlideRecord node, Boolean inclusive)

Retrieves all of the siblings of the given node.

Table 31. Parameters
Name Type Description
node GlideRecord Node whose siblings are to be retrieved
inclusive Boolean Indicator for whether to include the passed record in the returned records
Table 32. Returns
Type Description
GlideRecord List of siblings; ordered by child number

NestedIntervalUtils - getSubTreeRoot(GlideRecord node)

Returns the root of the direct sub tree in which the record resides.

Table 33. Parameters
Name Type Description
node GlideRecord Node whose sub-tree root is to be returned
Table 34. Returns
Type Description
GlideRecord Record for the sub-tree’s root [sub_tree_root]

NestedIntervalUtils - getTable()

Returns the name of the table to be queried.

Table 35. Parameters
Name Type Description
None
Table 36. Returns
Type Description
String Table name passed when constructing the utility

NestedIntervalUtils - getTopTask(GlideRecord node)

Returns the top task of the complete tree in which the record resides.

Table 37. Parameters
Name Type Description
node GlideRecord Node whose top task is to be returned
Table 38. Returns
Type Description
GlideRecord Record of the tree's top task

NestedIntervalUtils - initializeNode(GlideRecord newnode, String parentID)

Initializes a new node in the tree under a specified parent.

If no parent is defined, a new tree is created with the new node as the root.

Table 39. Parameters
Name Type Description
newNode GlideRecord Node to add
parentID String Parent of the new node
Table 40. Returns
Type Description
Boolean True, if node values were set correctly; otherwise, false.

NestedIntervalUtils - initializeSubTreeNode(GlideRecord newNode, String parentID)

Initializes a new node in the tree.

Sub trees are given a separate sub_tree_root but with the same top_task as the main tree.

Table 41. Parameters
Name Type Description
newNode GlideRecord New sub-tree root to be initialized
parentID String Parent of the new sub-tree root
Table 42. Returns
Type Description
Boolean True, if node values were set correctly; otherwise, false.

NestedIntervalUtils - moveNode(GlideRecord node, Number position)

Moves a node to the specified child position [child_position] under the parent.

For example, passing 3 as the position parameter moves the node to the third position in the list of children.

Table 43. Parameters
Name Type Description
node GlideRecord Node whose position is to be modified
position Number New child position [child_position] for the node under its parent
Table 44. Returns
Type Description
Number Status:
  • 1 = success
  • 2 = duplicate (relationship already exists)
  • 3 = recursive
  • 4 = invalid data
  • -1 = database error

NestedIntervalUtils - removeNode(GlideRecord node)

Removes the given node from the tree structure, but does not delete it.

Table 45. Parameters
Name Type Description
node GlideRecord Node to remove
Table 46. Returns
Type Description
void