Nuxeo Online Services

Javascript Expression Examples

Updated: October 22, 2018 Page Information Edit on GitHub

Javascript expressions are useful in two main use cases:

  1. To create filters that can be used either from Nuxeo Studio Designer or directly in your code using the nuxeo-filter element, in the expression property.
    They can be used to determine the suitable conditions to display an action, a menu from the left menu bar, any pages, and more globally, any element.

  2. To implement specific business logic, you can use Javascript expression in your custom automation chains and also in the Polymer section of your element.

Here is a list of the main Javascript expressions:

Criteria Javascript Expression
Document title document.title
Document type document.type
Document name document.path.substr(document.path.lastIndexOf('/') + 1)
Document version document.properties['uid:major_version']
Document property document.properties["<prefix>:<property_name>"]
Document is a version (not a live document) document.isVersion()
Document facet document.facets.indexOf(facet)
User ID user.id
User email user.email
User has permission on document user.hasPermission(document, '<permission>')
Group membership user.properties.groups.indexOf('<groupname>')

You can get more attributes from the Expression Editor available in Nuxeo Studio Modeler:

Javascript Expression Document
Javascript Expression Document

Javascript Expression User
Javascript Expression User

More options
You can also use Special NXQL Properties to build your expressions, and the Functions object.

From this list, you can compose some conditions:

Condition Javascript Expression
Document is a picture and the user has right permission doc.type !== 'Picture' && user.hasPermission(doc, 'Write')
Document doesn't have the "Retention" facet or its major version is under 1.0 document.facets.indexOf("Retention") < 0 || doc.properties['uid:major_version'] <= 1
User doesn't belong to the external group user.properties.groups.indexOf('external') < 0
22 days ago manonlumeau NXDOC-1650 fix about integrating changes, add mention on multiple attempts
History: Created by manonlumeau

We'd love to hear your thoughts!

All fields required