Node

Provides scripting facilities around a Node.

Properties

Name Type Description

associations

resultmap

All of the associations around a node.

attachments

object

The attachments for the node

branch

branch

The Branch on which this Association resides.

branchId

string

The ID of the branch that this Association resides on.

changesetId

string

The changeset ID on which this node resides. If the node has not yet been saved, this may be null.

childAssociations

resultmap

All of the child associations around a node

children

resultmap

All of the children of a node. This hands back the target nodes that are related by a:child associations against the given node.

description

string

The Description of this document.

id

string

The ID of this document.

parent

node

The parent of a node (as related by a:child)

properties

object

The properties for this document.

repository

repository

The Repository on which this Association resides.

repositoryId

string

The ID of the repository that this Association resides on.

title

string

The Title of this document.

type

string

The Type QName of the node (as a string)

typeQName

qname

The Type QName of the node.

Methods

addFeature

Usage

void addFeature()

Arguments

None

Return

Type Description

void


associate

Usage

void associate()

Arguments

None

Return

Type Description

void

Examples

Simple Association

In this code sample, we associate a node to a target node using the a:child association type.

var targetNode = branch.readNode("some_guid");
var association = node.associate(targetNode, "a:child");
Directed Association with Properties

In this code sample, we associate this node from a source node a:child association type and some custom properties. The custom properties are stored on the association.

var sourceNode = branch.readNode("some_guid");
var object = {
"weight": 3
};
var association = node.associate(targetNode, "a:child", "INCOMING", object);

del

Usage

void del()

Arguments

None

Return

Type Description

void


findAssociations

Usage

resultmap findAssociations()

Arguments

None

Return

Type Description

resultmap

Examples

In this code sample, we find any incoming associations for a node that are of type a:child. These associations start from a different node and point to our node.

var associations = node.findAssociations({
"direction": "INCOMING",
"type": "a:child"
});

The associations object is a key/value map where each key is the ID of an association. The value is the association itself.

for (var id in associations)
{
var association = associations[id];
logger.log("Found association: " + association.stringify(true));
}

getFeature

Usage

object getFeature()

Arguments

None

Return

Type Description

object


getIsContainer

Usage

whether the node is a container of "child" nodes getIsContainer()

Arguments

None

Return

Type Description

whether the node is a container of "child" nodes


getIsLocked

Usage

whether the node is locked getIsLocked()

Arguments

None

Return

Type Description

whether the node is locked


getPath

Usage

the default filefolder path for this node getPath()

Arguments

None

Return

Type Description

the default filefolder path for this node

Examples

In this code sample, we configure a script action for a rule bound with the p:afterAssociatePolicy which will apply a _path property to the target node if it has type my:thing:

function execute(association)
{
var node = association.getTargetNode();
if ("my:thing" === String(node.getType()))
{
logger.info("Applying path property for: " + node.getId());
var path = node.getPath();
if (path)
{
node.data["_path"] = path;
node.save();
}
}
}

reload

Usage

void reload()

Arguments

None

Return

Type Description

void

Examples

In this code sample, we make changes to a node and then reload to restore the original values.

// set the title to "Original Title"
node.properties.title = "Original Title";
node.save();

// change the title
node.properties.title = "Changed Title";

// reload
node.reload();

// the title is now "Original Title"
var test = (node.properties.title == "Original Title");
// test is true

remove

Usage

void remove()

Arguments

None

Return

Type Description

void


removeFeature

Usage

void removeFeature()

Arguments

None

Return

Type Description

void


save

Usage

void save()

Arguments

None

Return

Type Description

void

Examples

In this code sample, we make changes to a node and save the changes.

node.properties.title = "The new title of my node";
node.properties.category = "red";
node.save();

stringify

Usage

string stringify()

Arguments

None

Return

Type Description

string

Examples

In this code sample, we take the JSON for the given document and produce a string representation of it.

var text = document.stringify(true);

update

Usage

void update()

Arguments

None

Return

Type Description

void