×

Items

When working in the outline, the building blocks of your content are referred to as rows.

Rows can appear as simple as a line of text, but many outline styles also display other common components to the row such as handles, notes, and status checkboxes. Rows can also span multiple columns (if your document has more than one column).

In scripting terms, rows are items, which are instances of the Item class.

The Root Item

All rows in an outline are children or descendants of an invisible item called the the rootItem. The value of the rootItem property of the outline class, it is the invisible topmost item in the hierarchy of the topic column.

As shown in the illustration of hierarchical examples on this page, the rootItem is always the topmost element in the hierarchy.

NOTE: Since the document outline is the implied top of the hierarchy, the rootItem property can be used by itself without need to reference its parent outline, as in this script for getting the number of rows in the outline:

Root Item


rootItem.descendants.length

Referencing rootItem of a New Document

TIP: if your script needs to access the rootItem of a document created by the script itself, use the rootNode property of the current instance of the Editor class to derive the rootItem object of the new document. To avoid a name space conflict, do not store the referenced rootItem in a variable named “rootItem”, use a variable titled something like “baseItem” instead:

omnioutliner://localhost/omnijs-run?script=Document%2EmakeNewAndShow%28doc%20%3D%3E%20%7B%0D%09baseItem%20%3D%20doc%2Eeditors%5B0%5D%2ErootNode%2Eobject%0D%09baseItem%2EaddChild%28null%2C%20item%20%3D%3E%20%7Bitem%2Etopic%20%3D%20%27HELLO%20WORLD%27%7D%29%0D%7D%29%0D%0D
New Document with Row
 

Document.makeNewAndShow(doc => { baseItem = doc.editors[0].rootNode.object baseItem.addChild( null, item => { item.topic = 'HELLO WORLD' } ) })

Item “Relational” Properties

The items (rows) of an outline document have relationships that are defined using terms that are similar to those used to describe a human relationships in an ancestral hierarchy. For example, an item may have children, siblings, descendants, and ancestors. Here are the relational properties of the item class:

The illustrations below represent some of the relational properties of the Item class:

rootItem

rootItem.children

rootItem.descendants

rootItem.leaves

root root-children root-descendants root-leaves

item

item.children

item.descendants

item.leaves

root root-children root-descendants root-leaves

item.followingSiblings

item.precedingSiblings

item.parent

item.ancestors

root-children root-descendants root root-leaves

Item Instance Properties

Here are the properties of an instance of the Item class:

Since the value for identifier property is not able to be viewed in the document interface, here’s a script for displaying the ID of a selected outline item and placing a link to it on the clipboard. You can copy the ID from the dialog or from the console window.

omnioutliner://localhost/omnijs-run?script=items%20%3D%20document%2Eeditors%5B0%5D%2Eselection%2Eitems%0Dif%20%28items%2Elength%20%21%3D%3D%201%29%7B%0D%09errTitle%20%3D%20%27SELECTION%20ERROR%27%0D%09errMsg%20%3D%20%27Please%20select%20a%20single%20item%2E%27%0D%09alert%20%3D%20new%20Alert%28errTitle%2C%20errMsg%29%0D%09alert%2Eshow%28buttonIndex%20%3D%3E%20%7B%0D%09%09throw%20%7B%0D%09%09%09name%3A%20errTitle%2C%0D%09%09%09message%3A%20errMsg%0D%09%09%7D%0D%09%7D%29%0D%7D%20else%20%7B%0D%09itemID%20%3D%20items%5B0%5D%2Eidentifier%0D%09console%2Elog%28itemID%29%0D%09linkStr%20%3D%20%60omnioutliner%3A%2F%2F%2Fopen%3Frow%3D%24%7BitemID%7D%60%0D%09Pasteboard%2Egeneral%2Estring%20%3D%20linkStr%0D%09new%20Alert%28items%5B0%5D%2Etopic%2C%20itemID%29%2Eshow%28%29%0D%7D
Display Identifier of Selected Item
 

items = document.editors[0].selection.items if (items.length !== 1){ errTitle = 'SELECTION ERROR' errMsg = 'Please select a single item.' alert = new Alert(errTitle, errMsg) alert.show(buttonIndex => { throw { name: errTitle, message: errMsg } }) } else { itemID = items[0].identifier console.log(itemID) linkStr = `omnioutliner:///open?row=${itemID}` Pasteboard.general.string = linkStr new Alert(items[0].topic, itemID).show() }

You can create a link URL using the item identifier to switch to OmniOutliner and show the specified row. NOTE: item identifier links only work for the frontmost document, which must contain the targeted row.

Show a Specific Row using Identifier


itemID = "bHkiZI2Qms1" linkStr = `omnioutliner://localhost/open?row=${itemID}` URL.fromString(linkStr).open()
 

State Properties

The State properties are the value for the state property of the Item class and reflect the status of the checkbox field of the item:

IMPORTANT: The value of the state property of the Item class does not return accurate values. Use the state property of the ItemTreeNode (node) class instead:

omnioutliner://localhost/omnijs-run?script=selectedNodes%20%3D%20document%2Eeditors%5B0%5D%2EselectedNodes%0Dif%28selectedNodes%2Elength%20%3D%3D%3D%201%29%7B%0D%09selectedNode%20%3D%20selectedNodes%5B0%5D%0D%09if%28selectedNode%2Estate%20%3D%3D%3D%20State%2EChecked%29%7B%0D%09%09var%20message%20%3D%20%22Selected%20item%20state%20is%20checked%2E%22%0D%09%7D%20else%20if%20%28selectedNode%2Estate%20%3D%3D%3D%20State%2EMixed%29%7B%0D%09%09var%20message%20%3D%20%22Selected%20item%20state%20is%20mixed%2E%22%0D%09%7D%20else%20if%20%28selectedNode%2Estate%20%3D%3D%3D%20State%2EUnchecked%29%7B%0D%09%09var%20message%20%3D%20%22Selected%20item%20state%20is%20unchecked%2E%22%0D%09%7D%0D%09new%20Alert%28%27ITEM%20STATE%27%2C%20message%29%2Eshow%28%29%0D%7D
State of Selected Item
 

selectedNodes = document.editors[0].selectedNodes if(selectedNodes.length === 1){ selectedNode = selectedNodes[0] if(selectedNode.state === State.Checked){ var message = "Selected item state is checked." } else if (selectedNode.state === State.Mixed){ var message = "Selected item state is mixed." } else if (selectedNode.state === State.Unchecked){ var message = "Selected item state is unchecked." } new Alert('ITEM STATE', message).show() }

An alternative technique is to use the nodeForObject() function of the Editor class to derive the corresponding node for the selected item:

omnioutliner://localhost/omnijs-run?script=var%20editor%20%3D%20document%2Eeditors%5B0%5D%0DselectedItems%20%3D%20editor%2Eselection%2Eitems%0Dif%28selectedItems%2Elength%20%3D%3D%3D%201%29%7B%0D%09selectedItem%20%3D%20selectedItems%5B0%5D%0D%09selectedNode%20%3D%20editor%2EnodeForObject%28selectedItem%29%0D%09if%28selectedNode%2Estate%20%3D%3D%3D%20State%2EChecked%29%7B%0D%09%09var%20message%20%3D%20%22Selected%20item%20state%20is%20checked%2E%22%0D%09%7D%20else%20if%20%28selectedNode%2Estate%20%3D%3D%3D%20State%2EMixed%29%7B%0D%09%09var%20message%20%3D%20%22Selected%20item%20state%20is%20mixed%2E%22%0D%09%7D%20else%20if%20%28selectedNode%2Estate%20%3D%3D%3D%20State%2EUnchecked%29%7B%0D%09%09var%20message%20%3D%20%22Selected%20item%20state%20is%20unchecked%2E%22%0D%09%7D%0D%09new%20Alert%28%27ITEM%20STATE%27%2C%20message%29%2Eshow%28%29%0D%7D
State of Selected Node (Item)
 

var editor = document.editors[0] selectedItems = editor.selection.items if(selectedItems.length === 1){ selectedItem = selectedItems[0] selectedNode = editor.nodeForObject(selectedItem) if(selectedNode.state === State.Checked){ var message = "Selected item state is checked." } else if (selectedNode.state === State.Mixed){ var message = "Selected item state is mixed." } else if (selectedNode.state === State.Unchecked){ var message = "Selected item state is unchecked." } new Alert('ITEM STATE', message).show() }

Here’s a script that focuses the checked items:

omnioutliner://localhost/omnijs-run?script=editor%20%3D%20document%2Eeditors%5B0%5D%0Dtree%20%3D%20document%2Eoutline%0D%0DcheckedItems%20%3D%20tree%2ErootItem%2Edescendants%2Efilter%28item%20%3D%3E%20%7B%0D%09node%20%3D%20editor%2EnodeForObject%28item%29%0D%09if%28node%2Estate%20%21%3D%3D%20State%2EUnchecked%29%7B%0D%09%09return%20item%0D%09%7D%0D%7D%29%0D%0Dif%28checkedItems%2Elength%20%3E%200%29%7B%0D%09editor%2EfocusedItems%20%3D%20checkedItems%0D%7D
Focus Checked Items
 

editor = document.editors[0] tree = document.outline checkedItems = tree.rootItem.descendants.filter(item => { node = editor.nodeForObject(item) if(node.state !== State.Unchecked){ return item } }) if(checkedItems.length > 0){ editor.focusedItems = checkedItems }

Functions of the Item Class

Here are the methods used with an instance of the Item class:

Here’s short script that uses the valueForColumn() method to copy the contents of a column into the notes field of each top-level row.

rootItem.children.forEach(item => { item.note = item.valueForColumn(columns.byTitle('Title of Column to Copy')).string })
Copy Text of Column Cell to Item Note


var columnRef = columns.byTitle('Title of Column to Copy') rootItem.children.forEach(item => { item.note = item.valueForColumn(columnRef).string })

Here’s a script that uses the remove() function to delete all descendants of the selected item:

omnioutliner://localhost/omnijs-run?script=var%20editor%20%3D%20document%2Eeditors%5B0%5D%0DselectedItems%20%3D%20editor%2Eselection%2Eitems%0Dif%28selectedItems%2Elength%20%3D%3D%3D%201%29%7B%0D%09selectedItem%20%3D%20selectedItems%5B0%5D%0D%09selectedItem%2Edescendants%2EforEach%28item%20%3D%3E%20%7B%0D%09%09item%2Eremove%28%29%0D%09%7D%29%0D%7D
Delete Descendants of Selected Item
 

var editor = document.editors[0] selectedItems = editor.selection.items if(selectedItems.length === 1){ selectedItem = selectedItems[0] selectedItem.descendants.forEach(item => { item.remove() }) }

Getting Selected Items

Object references to the selected items can be acquired using the Selection instance of the current Editor object. IF no items are selected, the result will be an empty array.

Get Selected Items


selectedItems = document.editors[0].selection.items

References to selected outline items can also be acquired through the use of the selectedNodes property of the Editor class. The value of this property is an array of TreeNodes instances. The item represented by a TreeNode is accessed through the object property of the TreeNode instance.

Using the map() method is an efficient means for deriving an array of selected item objects from their corresponding Treenode (Node) instances:

Get Selected Node Objects (Items)


editor = document.editors[0] selectedItems = editor.selectedNodes.map(node => node.object)

A basic script for processing the selected items:

Process Selected Items


selectedItems = document.editors[0].selection.items if (selectedItems.length === 0){ errTitle = 'SELECTION ERROR' errMesssage = 'No items are selected.' new Alert(errTitle, errMesssage).show() } else { // process items }

The following script creates and displays an Alert dialog showing the text (topic) of the single selected item:

Text of Single Selected Item


selectedItems = document.editors[0].selection.items if (selectedItems.length !== 1){ errTitle = 'SELECTION ERROR' errMesssage = 'Please select a single item.' new Alert(errTitle, errMesssage).show() } else { // process item selectedItem = selectedItems[0] new Alert('Item Text',selectedItem.topic).show() }

The topic property of the Item class (shown above) is provided as a way to make it easier for scripts to retrieve and set the value of the topic column (outlineColumn) of an item.

The following script shows how the value of a specified column is retrieved using the valueForColumn() method. Compare it to the version above.

Text of Single Selected Item (Alternate)


selectedItems = document.editors[0].selection.items if (selectedItems.length !== 1){ var errTitle = 'SELECTION ERROR' var errMesssage = 'Please select a single item.' new Alert(errTitle, errMesssage).show() } else { // process item selectedItem = selectedItems[0] targetColumn = document.outline.outlineColumn itemValue = selectedItem.valueForColumn(targetColumn).string new Alert('Item Text',itemValue).show() }

Getting Outline Contents (text)

The following example scripts demonstrate two techniques for extracting the text contents of the outline topics, inserting tab characters for outline indents:

Iterating Descendants


var topics = new Array() var indent = '\t' rootItem.descendants.forEach(item => { level = item.level if (level > 1){ var itemString = indent.repeat(level-1) + item.topic } else { var itemString = item.topic } topics.push(itemString) }) Pasteboard.general.string = topics.join('\n')

Calling the apply() function on the rootItem:

Using the apply() Function


var topics = new Array() var indent = '\t' rootItem.apply(item => { level = item.level if (level > 1){ var itemString = indent.repeat(level-1) + item.topic } else { var itemString = item.topic } topics.push(itemString) }) Pasteboard.general.string = topics.join('\n')

TIP: To retrieve the complete contents of the outline as text, including notes, create a file wrapper for the “plain text” file type and retrieve its data as text:

omnioutliner://localhost/omnijs-run?script=%28async%20%28%29%20%3D%3E%20%7B%0D%09fileTypeID%20%3D%20%22public%2Eplain%2Dtext%22%0D%09baseName%20%3D%20%22Text%20Export%22%0D%09wrapper%20%3D%20await%20document%2EmakeFileWrapper%28baseName%2C%20fileTypeID%29%0D%09Pasteboard%2Egeneral%2Estring%20%3D%20wrapper%2Econtents%2EtoString%28%29%0D%7D%29%28%29%3B
Full Outline as Text
 

(async () => { fileTypeID = "public.plain-text" baseName = "Text Export" wrapper = await document.makeFileWrapper(baseName, fileTypeID) Pasteboard.general.string = wrapper.contents.toString() })();

TIP: Using the Share Panel to export the outline as text to Mail, Messages, Notes, or 3rd-Party applications:

omnioutliner://localhost/omnijs-run?script=%28async%20%28%29%20%3D%3E%20%7B%0D%09fileTypeID%20%3D%20%22public%2Eplain%2Dtext%22%0D%09baseName%20%3D%20%22Text%20Export%22%0D%09wrapper%20%3D%20await%20document%2EmakeFileWrapper%28baseName%2C%20fileTypeID%29%0D%09new%20SharePanel%28%5Bwrapper%2Econtents%2EtoString%28%29%5D%29%2Eshow%28%29%0D%7D%29%28%29%3B
Export the Outline as Text
 

(async () => { fileTypeID = "public.plain-text" baseName = "Text Export" wrapper = await document.makeFileWrapper(baseName, fileTypeID) new SharePanel([wrapper.contents.toString()]).show() })();
 

Adding Items

Items (rows) are added to an outline using the addChild() method:

For example, here’s how to add an empty top-level item (row) to the end of the outline by calling the addChild() method on the rootItem. The resulting object reference to the newly created item is returned and copied into the variable: newRow

omnioutliner://localhost/omnijs-run?script=newRow%20%3D%20rootItem%2EaddChild%28%29
New Row at End of Outline
 

newRow = rootItem.addChild()

A variation of the previous script that manually sets the value of the topic property after creation of the item:

omnioutliner://localhost/omnijs-run?script=newRow%20%3D%20rootItem%2EaddChild%28%29%0DnewRow%2Etopic%20%3D%20%22How%20Now%20Brown%20Cow%22
New Row with Topic
 

newRow = rootItem.addChild() newRow.topic = "How Now Brown Cow"

An example using the parameters of the addChild() function to create a new row with topic:

omnioutliner://localhost/omnijs-run?script=newRow%20%3D%20rootItem%2EaddChild%28%0D%09null%2C%0D%09item%20%3D%3E%20%7B%0D%09%09item%2Etopic%20%3D%20%22New%20Row%22%0D%09%7D%0D%29
Append New Top-Level Row
 

newRow = rootItem.addChild( null, item => { item.topic = "New Row" } )

Adding a new row to the end of the outline and then selecting the newly added row by addressing the current instance of the Editor class:

omnioutliner://localhost/omnijs-run?script=newRow%20%3D%20rootItem%2EaddChild%28%0D%09null%2C%0D%09item%20%3D%3E%20%7B%0D%09%09item%2Etopic%20%3D%20%22New%20Row%22%0D%09%7D%0D%29%0Deditor%20%3D%20document%2Eeditors%5B0%5D%0Dnode%20%3D%20editor%2EnodeForObject%28newRow%29%0Deditor%2Eselect%28%5Bnode%5D%2C%20false%29
Append and Select New Top-Level Row
 

newRow = rootItem.addChild( null, item => { item.topic = "New Row" } ) editor = document.editors[0] node = editor.nodeForObject(newRow) editor.select([node], false)

Inserting a new row at the beginning of the outline and then selecting the newly added row by addressing the current instance of the Editor class. Note the position indicator (in Red) included in the function:

omnioutliner://localhost/omnijs-run?script=newRow%20%3D%20rootItem%2EaddChild%28%0D%09rootItem%2Ebeginning%2C%0D%09item%20%3D%3E%20%7B%0D%09%09item%2Etopic%20%3D%20%22New%20Row%22%0D%09%7D%0D%29%0Deditor%20%3D%20document%2Eeditors%5B0%5D%0Dnode%20%3D%20editor%2EnodeForObject%28newRow%29%0Deditor%2Eselect%28%5Bnode%5D%2C%20false%29
Prepend and Select New Top-Level Row
 

newRow = rootItem.addChild( rootItem.beginning, item => { item.topic = "New Row" } ) editor = document.editors[0] node = editor.nodeForObject(newRow) editor.select([node], false)

BONUS: this variation uses the Item instance’s style property and Style.Attribute class to insert and select a new styled row at the beginning of the outline:

omnioutliner://localhost/omnijs-run?script=newRow%20%3D%20rootItem%2EaddChild%28%0D%09rootItem%2Ebeginning%2C%0D%09item%20%3D%3E%20%7B%0D%09%09item%2Etopic%20%3D%20%22THIS%20IS%20IMPORTANT%20BECAUSE%20IT%20IS%20RED%21%22%0D%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Ered%29%20%0D%09%7D%0D%29%0Deditor%20%3D%20document%2Eeditors%5B0%5D%0Dnode%20%3D%20editor%2EnodeForObject%28newRow%29%0Deditor%2Eselect%28%5Bnode%5D%2C%20false%29
Insert and Select New Styled Row
 

newRow = rootItem.addChild( rootItem.beginning, item => { item.topic = "THIS IS IMPORTANT BECAUSE IT IS RED!" item.style.set(Style.Attribute.FontFillColor, Color.red) } ) editor = document.editors[0] node = editor.nodeForObject(newRow) editor.select([node], false)
 

Item Position Properties

The item position properties are used to identify the position of a child item within its parental hierarchy.

The following scripts are examples using the ItemPosition class position properties. In each example, a new item (child) is created using the addChild() instance method, which takes as its parameters, the item position at which the new item is added, and an optional function for manipulating the created item.

(⬇ see below ) The example insertion locations used to insert a new child row into a selected row:

Results of each of the previous examples displayed side-by-side

If you wish to try the examples yourself, run the following script for creating the demonstration document:

omnioutliner://localhost/omnijs-run?script=Document%2EmakeNewAndShow%28doc%20%3D%3E%20%7B%0D%09baseItem%20%3D%20doc%2Eeditors%5B0%5D%2ErootNode%2Eobject%0D%09baseItem%2EaddChild%28null%2Cfunction%28item%29%7B%0D%09%09item%2Etopic%20%3D%20%27Aquire%27%0D%09%09item%2EaddChild%28null%2C%20itm%20%3D%3E%20%7B%20itm%2Etopic%20%3D%20%22Selection%22%7D%29%0D%09%09item%2EaddChild%28null%2C%20itm%20%3D%3E%20%7B%20itm%2Etopic%20%3D%20%22Input%22%7D%29%0D%09%09item%2EaddChild%28null%2C%20itm%20%3D%3E%20%7B%20itm%2Etopic%20%3D%20%22Prompt%22%7D%29%0D%09%7D%29%0D%09baseItem%2EaddChild%28null%2Cfunction%28item%29%7B%0D%09%09item%2Etopic%20%3D%20%27Process%27%0D%09%09item%2EaddChild%28null%2C%20itm%20%3D%3E%20%7B%20itm%2Etopic%20%3D%20%22Flexible%20Workflow%22%7D%29%0D%09%09item%2EaddChild%28null%2C%20itm%20%3D%3E%20%7B%20itm%2Etopic%20%3D%20%22User%20Interaction%22%7D%29%0D%09%7D%29%0D%09baseItem%2EaddChild%28null%2Cfunction%28item%29%7B%0D%09%09item%2Etopic%20%3D%20%27Distribute%27%0D%09%09item%2EaddChild%28null%2C%20itm%20%3D%3E%20%7B%20itm%2Etopic%20%3D%20%22Local%22%7D%29%0D%09%09item%2EaddChild%28null%2C%20itm%20%3D%3E%20%7B%20itm%2Etopic%20%3D%20%22Network%22%7D%29%0D%09%7D%29%0D%09doc%2Eoutline%2EbaseStyle%2Eclear%28%29%0D%09bColor%20%3D%20Color%2ERGB%280%2E193246%2C%200%2E193246%2C%200%2E193246%2C%201%2E0%29%0D%09doc%2Eoutline%2EbaseStyle%2Eset%28Style%2EAttribute%2EBackgroundColor%2C%20bColor%29%0D%09doc%2Eoutline%2EbaseStyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Ewhite%29%0D%09doc%2Eoutline%2EbaseStyle%2Eset%28Style%2EAttribute%2EFontFamily%2C%20%27Tahoma%27%29%0D%09doc%2Eoutline%2EbaseStyle%2Eset%28Style%2EAttribute%2EParagraphLineHeightMultiple%2C%201%2E1%29%0D%09doc%2Eoutline%2ElevelStyle%280%29%2Eset%28Style%2EAttribute%2EFontSize%2C%2026%29%0D%09doc%2Eoutline%2ElevelStyle%280%29%2Eset%28Style%2EAttribute%2EParagraphLineHeightMultiple%2C%201%2E2%29%0D%09doc%2Eoutline%2ElevelStyle%281%29%2Eset%28Style%2EAttribute%2EFontSize%2C%2018%29%0D%09editor%20%3D%20doc%2Eeditors%5B0%5D%0D%09editor%2ErootNode%2Echildren%2EforEach%28node%20%3D%3E%20%7Bnode%2Eexpand%28%29%7D%29%0D%7D%29%0D
Create New Demo Document
 

Document.makeNewAndShow(doc => { baseItem = doc.editors[0].rootNode.object baseItem.addChild(null, item => { item.topic = 'Aquire' item.addChild(null, itm => {itm.topic = "Selection"}) item.addChild(null, itm => {itm.topic = "Input"}) item.addChild(null, itm => {itm.topic = "Prompt"}) }) baseItem.addChild(null, item => { item.topic = 'Process' item.addChild(null, itm => {itm.topic = "Flexible Workflow"}) item.addChild(null, itm => {itm.topic = "User Interaction"}) }) baseItem.addChild(null, item => { item.topic = 'Distribute' item.addChild(null, itm => {itm.topic = "Local"}) item.addChild(null, itm => {itm.topic = "Network"}) }) doc.outline.baseStyle.clear() bColor = Color.RGB(0.193246, 0.193246, 0.193246, 1.0) doc.outline.baseStyle.set(Style.Attribute.BackgroundColor, bColor) doc.outline.baseStyle.set(Style.Attribute.FontFillColor, Color.white) doc.outline.baseStyle.set(Style.Attribute.FontFamily, 'Tahoma') doc.outline.baseStyle.set(Style.Attribute.ParagraphLineHeightMultiple, 1.1) doc.outline.levelStyle(0).set(Style.Attribute.FontSize, 26) doc.outline.levelStyle(0).set(Style.Attribute.ParagraphLineHeightMultiple, 1.2) doc.outline.levelStyle(1).set(Style.Attribute.FontSize, 18) editor = doc.editors[0] editor.rootNode.children.forEach(node => {node.expand()}) })

EX 1) Using the after Property

The first positional example will demonstrate how to add a row (child) after the second row (child) of selected item.

Note the use of the children property to list the items contained in the selected item’s hierarchy. Since the first item in a JavaScript array (list) has an index of “0”, the use of the integer “1” indicates the second item in the array of child rows.

Also note the use of the after positional property to indicate where the new row should be created.

DO THIS ►

Once the new document is created, select the first top-level item (row) titled “Aquire” and click the “Run Script” button.

omnioutliner://localhost/omnijs-run?script=var%20editor%20%3D%20document%2Eeditors%5B0%5D%0DselectedItems%20%3D%20editor%2Eselection%2Eitems%0Dif%28selectedItems%2Elength%20%3D%3D%3D%201%29%7B%0D%09selectedItem%20%3D%20selectedItems%5B0%5D%0D%09newRow%20%3D%20selectedItem%2EaddChild%28%0D%09%09selectedItem%2Echildren%5B1%5D%2Eafter%2C%0D%09%09item%20%3D%3E%20%7B%0D%09%09%09item%2Etopic%20%3D%20%22NEW%20THIRD%20CHILD%22%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Eyellow%29%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontWeight%2C%209%29%0D%09%09%7D%0D%09%29%0D%09editor%2Eselect%28%5Beditor%2EnodeForObject%28newRow%29%5D%2C%20false%29%0D%7D
Insert Row After 2nd Child of Selected Row
 

var editor = document.editors[0] selectedItems = editor.selection.items if(selectedItems.length === 1){ selectedItem = selectedItems[0] newRow = selectedItem.addChild( selectedItem.children[1].after, item => { item.topic = "NEW THIRD CHILD" item.style.set(Style.Attribute.FontFillColor, Color.yellow) item.style.set(Style.Attribute.FontWeight, 9) } ) editor.select([editor.nodeForObject(newRow)], false) }

A new row titled “NEW THIRD CHILD” will be inserted into the selected item’s hierarchy after the second child row.

DO THIS ►

Before proceeding to the next example, use the “Undo” command from the “Edit” menu to revert the document back to its initial state. Leave the first row selected.

EX 2) Using the before Property

This example will demonstrates how to add a row (child) before the second row (child) of selected item. Note the use of the before positional property.

omnioutliner://localhost/omnijs-run?script=var%20editor%20%3D%20document%2Eeditors%5B0%5D%0DselectedItems%20%3D%20editor%2Eselection%2Eitems%0Dif%28selectedItems%2Elength%20%3D%3D%3D%201%29%7B%0D%09selectedItem%20%3D%20selectedItems%5B0%5D%0D%09newRow%20%3D%20selectedItem%2EaddChild%28%0D%09%09selectedItem%2Echildren%5B1%5D%2Ebefore%2C%0D%09%09item%20%3D%3E%20%7B%0D%09%09%09item%2Etopic%20%3D%20%22NEW%20SECOND%20CHILD%22%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Eyellow%29%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontWeight%2C%209%29%0D%09%09%7D%0D%09%29%0D%09editor%2Eselect%28%5Beditor%2EnodeForObject%28newRow%29%5D%2C%20false%29%0D%7D
Insert Row Before 2nd Child of Selected Row
 

var editor = document.editors[0] selectedItems = editor.selection.items if(selectedItems.length === 1){ selectedItem = selectedItems[0] newRow = selectedItem.addChild( selectedItem.children[1].before, item => { item.topic = "NEW SECOND CHILD" item.style.set(Style.Attribute.FontFillColor, Color.yellow) item.style.set(Style.Attribute.FontWeight, 9) } ) editor.select([editor.nodeForObject(newRow)], false) }

EX 3) Using the beginning Property

This example will demonstrates how to insert a row (child) add child at the beginning of children of selected item. Note the use of the beginning positional property.

omnioutliner://localhost/omnijs-run?script=var%20editor%20%3D%20document%2Eeditors%5B0%5D%0DselectedItems%20%3D%20editor%2Eselection%2Eitems%0Dif%28selectedItems%2Elength%20%3D%3D%3D%201%29%7B%0D%09selectedItem%20%3D%20selectedItems%5B0%5D%0D%09newRow%20%3D%20selectedItem%2EaddChild%28%0D%09%09selectedItem%2Ebeginning%2C%0D%09%09item%20%3D%3E%20%7B%0D%09%09%09item%2Etopic%20%3D%20%22NEW%20BEGINNING%20ITEM%22%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Eyellow%29%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontWeight%2C%209%29%0D%09%09%7D%0D%09%29%0D%09editor%2Eselect%28%5Beditor%2EnodeForObject%28newRow%29%5D%2C%20false%29%0D%7D
Insert Row at Beginning of Children of Selected Row
 

var editor = document.editors[0] selectedItems = editor.selection.items if(selectedItems.length === 1){ selectedItem = selectedItems[0] newRow = selectedItem.addChild( selectedItem.beginning, item => { item.topic = "NEW BEGINNING ITEM" item.style.set(Style.Attribute.FontFillColor, Color.yellow) item.style.set(Style.Attribute.FontWeight, 9) } ) editor.select([editor.nodeForObject(newRow)], false) }

EX 4) Using the end Property

This example will demonstrates how to insert a row (child) add child at the end of children of selected item. Note the use of the end positional property.

omnioutliner://localhost/omnijs-run?script=var%20editor%20%3D%20document%2Eeditors%5B0%5D%0DselectedItems%20%3D%20editor%2Eselection%2Eitems%0Dif%28selectedItems%2Elength%20%3D%3D%3D%201%29%7B%0D%09selectedItem%20%3D%20selectedItems%5B0%5D%0D%09newRow%20%3D%20selectedItem%2EaddChild%28%0D%09%09selectedItem%2Eend%2C%0D%09%09item%20%3D%3E%20%7B%0D%09%09%09item%2Etopic%20%3D%20%22NEW%20ENDING%20ITEM%22%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Eyellow%29%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontWeight%2C%209%29%0D%09%09%7D%0D%09%29%0D%09editor%2Eselect%28%5Beditor%2EnodeForObject%28newRow%29%5D%2C%20false%29%0D%7D
Insert Row at End of Children of Selected Row
 

var editor = document.editors[0] selectedItems = editor.selection.items if(selectedItems.length === 1){ selectedItem = selectedItems[0] newRow = selectedItem.addChild( selectedItem.end, item => { item.topic = "NEW ENDING ITEM" item.style.set(Style.Attribute.FontFillColor, Color.yellow) item.style.set(Style.Attribute.FontWeight, 9) } ) editor.select([editor.nodeForObject(newRow)], false) }

Working with Siblings

When creating an item position for a sibling of an item, use the parent property to reference the parent of the item and use the item’s position to indicate where the new item should be inserted.

DO THIS ►

For the following sibling examples, select the second child, titled “Input”, of the first top-level row in the demo document, before running the examples.

(⬇ see below ) The example insertion locations used to add siblings before and after a selected row:

Screenshot

EX 5) Preceding Sibling

This script will create a new item, before the selected item, at the same level of the selected item (sibling).

omnioutliner://localhost/omnijs-run?script=var%20editor%20%3D%20document%2Eeditors%5B0%5D%0DselectedItems%20%3D%20editor%2Eselection%2Eitems%0Dif%28selectedItems%2Elength%20%3D%3D%3D%201%29%7B%0D%09selectedItem%20%3D%20selectedItems%5B0%5D%0D%09selectedItemParent%20%3D%20selectedItem%2Eparent%0D%09newRow%20%3D%20selectedItemParent%2EaddChild%28%0D%09%09selectedItem%2Ebefore%2C%0D%09%09item%20%3D%3E%20%7B%0D%09%09%09item%2Etopic%20%3D%20%22NEW%20PRECEDING%20SIBLING%20ITEM%22%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Eyellow%29%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontWeight%2C%209%29%0D%09%09%7D%0D%09%29%0D%09editor%2Eselect%28%5Beditor%2EnodeForObject%28newRow%29%5D%2C%20false%29%0D%7D
Adding a Preceding Sibling
 

var editor = document.editors[0] selectedItems = editor.selection.items if(selectedItems.length === 1){ selectedItem = selectedItems[0] selectedItemParent = selectedItem.parent newRow = selectedItemParent.addChild( selectedItem.before, item => { item.topic = "NEW PRECEDING SIBLING ITEM" item.style.set(Style.Attribute.FontFillColor, Color.yellow) item.style.set(Style.Attribute.FontWeight, 9) } ) editor.select([editor.nodeForObject(newRow)], false) }

EX 6) Following Sibling

This script will create a new item, after the selected item, at the same level of the selected item (sibling).

omnioutliner://localhost/omnijs-run?script=var%20editor%20%3D%20document%2Eeditors%5B0%5D%0DselectedItems%20%3D%20editor%2Eselection%2Eitems%0Dif%28selectedItems%2Elength%20%3D%3D%3D%201%29%7B%0D%09selectedItem%20%3D%20selectedItems%5B0%5D%0D%09selectedItemParent%20%3D%20selectedItem%2Eparent%0D%09newRow%20%3D%20selectedItemParent%2EaddChild%28%0D%09%09selectedItem%2Eafter%2C%0D%09%09item%20%3D%3E%20%7B%0D%09%09%09item%2Etopic%20%3D%20%22NEW%20FOLLOWING%20SIBLING%20ITEM%22%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontFillColor%2C%20Color%2Eyellow%29%0D%09%09%09item%2Estyle%2Eset%28Style%2EAttribute%2EFontWeight%2C%209%29%0D%09%09%7D%0D%09%29%0D%09editor%2Eselect%28%5Beditor%2EnodeForObject%28newRow%29%5D%2C%20false%29%0D%7D
Adding a Following Sibling
 

var editor = document.editors[0] selectedItems = editor.selection.items if(selectedItems.length === 1){ selectedItem = selectedItems[0] selectedItemParent = selectedItem.parent newRow = selectedItemParent.addChild( selectedItem.after, item => { item.topic = "NEW FOLLOWING SIBLING ITEM" item.style.set(Style.Attribute.FontFillColor, Color.yellow) item.style.set(Style.Attribute.FontWeight, 9) } ) editor.select([editor.nodeForObject(newRow)], false) }