Cloud CMS lets you bind custom behaviors to content policies. Using this mechanism, you can set up the behavior of your content instances and content types to implement your exact content requirements.

Content Policies

For all intents and purposes, a content policy is the name of an event that gets raised by Cloud CMS when an activity occurs to your content. Here is a list of some common policies:

Policy QName Description
p:beforeCreateNode Raised before a piece of content is created
p:afterCreateNode Raised after a piece of content has been created and committed to the branch
p:beforeUpdateNode Raised before a piece of content is updated
p:afterUpdateNode Raised after a piece of content has been updated and committed to the branch
p:beforeDeleteNode Raised before a piece of content is deleted
p:afterDeleteNode Raised after a piece of content has been deleted and removed from the branch
p:beforeAssociate Raised before two nodes are associated together
p:afterAssociate Raised after two nodes have been associated and the association has been committed to the branch
p:beforeUnassociate Raised before two nodes are unassociated from each other
p:afterUnassociate Raised after two nodes have been unassociated from each other in the branch
p:beforeCreateUpdateAttachment Raised before an attachment is added to a node
p:afterCreateUpdateAttachment Raised after an attachment has been added to a node and committed to the branch
p:beforeDeleteAttachment Raised before an attachment has been deleted from a node
p:afterDeleteAttachment Raised after an attachment has been delete from a node and committed to the branch


In Cloud CMS, a behavior is either a Rule or a Script. Rules are conditional actions defined within the Cloud CMS rules engine for your branch. Scripts are server-side JavaScript files that implement interfaces to handle the policy events. Unlike Rules, Scripts do not allow for wizard and configuration-based management of conditions and actions. Rather, Scripts are simply code - you write them and do anything you want inside of them.

All behaviors in Cloud CMS must be tagged with the f:behavior feature.

Binding Behaviors

Behaviors can be bound either to content instances or content types. When bound to a content instance, only manipulations of that specific content instance will trigger the behavior. However, when bound to a content type, all content instances of that type will be affected.

To bind a behavior, create a a:has_behavior association between your source node (either a content instance or a content type) and the behavior (either a Rule or a Script). In doing so, you must provide two properties on the association:

  • policy - the QName of the policy, such as p:beforeCreateNode
  • scope - either 0 (for instance binding) or 1 (for type binding)

Save your association. Cloud CMS will automatically re-compile the policies for your branch. For all subsequent operations against the branch, the policy system will trigger your behavior.

Script Interfaces

If you elect to write scripts to implement custom behaviors, the following signatures can be used inside of your JavaScript:

Node Policies

function beforeCreateNode(node) { }
function afterCreateNode(node) { }
function beforeUpdateNode(node) { }
function afterUpdateNode(node) { }
function beforeDeleteNode(node) { }
function afterDeleteNode(node) { }

Association Policies

function beforeAssociate(association) { }
function afterAssociate(association) { }
function beforeUnassociate(association) { }
function afterUnassociate(association) { }

Attachment Policies

function beforeCreateUpdateAttachment(node, attachmentId, contentType, filename) { }
function afterCreateUpdateAttachment(node, attachment) { }
function beforeDeleteAttachment(node, attachment) { }
function afterDeleteAttachment(node, attachment) { }

An Example - Script Behavior

In this example, we'll define a behavior that maintains a counter for us. The counter will count the number of times that a document has been updated. We'll then register this behavior so that it triggers whenever content of a particular type is updated.

Define the Behavior using JavaScript

Let's start by creating the behavior. We'll do this using server-side JavaScript. Go to Documents and launch the Create a Document action. When the wizard pops up, pick n:node. That's right, our behavior is just a simple old boring node.

Give your behavior node the title Increment Counter and save it. Then, click into it and click on Editor. Set the content type to script/javascript and provide the method implementation for the p:beforeUpdateNode policy.

And then click Save.

As you can see, the actual JavaScript is pretty light.

function beforeUpdateNode(node)
    if (!node.data.counter) {
        node.data.counter = 0;


This defines a handler for the p:beforeCreateNode policy and uses the same method name (which is required). The method takes in the node being updated and makes sure there is a counter key/value initialized to zero. It increments the counter each time it runs.

Now let's mark this JavaScript node as a behavior. That way, Cloud CMS knows how to work with it. Click on Features.

And then click on Add Feature. Pick the f:behavior feature. In the JSON configuration for the feature, just set enabled to true. Like this:

And then click Add Feature to save things.

Create the Article Type

Now let's create a simple content type for an article. We'll then bind our behavior to the content type so that all of the articles we create will automatically have this counter logic applied to them.

We create a project in Cloud CMS and then go to the definitions page to create a definition with QName my:article.

The article now appears in our list of content types.

We click on the article and edit it's JSON. We can use JSON Schema here to define any properties that we like. Let's keep it simple since the point of this exercise isn't really to model out something cool (see the section on Content Modeling for that)! Rather, let's just define title and description, like this:

Be sure to save any changes to your content type.

Bind the Behavior to the Content Type

We're not done with the content type yet. Click on Associations.

And then click on Add Association. Here, we create an association between our Content Type node and the Behavior node. The association should be of type Has Behavior (a:has_behavior). Use the Select... button to find and pick your Increment Counter behavior.

Furthermore, we need to supply some additional properties that are stored on the association, as shown here:

The additional properties are:

    "policy": "p:beforeUpdateNode",
    "scope": 1

The policy property lets the association know which policy method is being overridden. The scope property defines the intersection point for the policy method override. To override a content instance's behaviors, the value should be set to 0. To override all content instances for a content type, the value should be set to 1. Note that a value of 1 only applies to content type nodes.

Click Add Association to lock things into place.

Try it out

In the previous steps, we've overridden a behavior for all instances of a content type. Whenever any instance of the content type my:article is updated, a counter will be maintained and incremented automatically.

To try it, go to Documents and create an article. To do so, click on Create a Document and pick the type My Article.

Enter anything you'd like for Title and Description and then click Create.

Now click on your Article to open up the overview screen. On the right-hand side, you'll see a Properties panel.

Same old standard properties, right? That's because we haven't updated our article yet. Remember that our policy override won't trigger until we do an update to the article. To update, click on Touch Document on the actions menu on the right-hand side.

Your screen will refresh and you'll see that the counter property has incremented to 1.

Click on Touch Documents a few more times. Your counter will kindly increment for you.

That's it. Your behavior is in place and will run automatically for all update operations against any and all content instances of type my:article.