Nuxeo Online Services

Javascript Expression Examples

Updated: March 8, 2019 Page Information Edit on GitHub

Javascript expressions are useful in various 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.

  3. To map parameters from a page provider NXQL query into the corresponding variables. In this context, Javascript variables need to be provided as a Javascript object, e.g. {"key1": "value1", "key2": "value2"}. For a detailed example using them, you may refer to How to Display a Children Documents Listing.

Here is a list of the main Javascript expressions:

Criteria Javascript Expression Corresponding Content View Query Parameter
Document title document.title #{currentDocument.dc.title}
Document id document.uuid #{}
Document type document.type #{currentDocument.type}
Document name document.path.substr(document.path.lastIndexOf('/') + 1) #{}
Document version['uid:major_version']['uid:minor_version']
Document property["<prefix>:<property_name>"] #{currentDocument.< prefix >.< property_name >}
Document is a version (not a live document) document.isVersion() #{currentDocument.isVersion}
Document has facet document.facets.indexOf('facet') #{currentDocument.hasFacet('facet')}
User ID #{}
User email #{}
User has permission on document user.hasPermission(document, '<permission>') #{nxd:hasPermission(document, '< permission >')}
Group membership'< groupname >') #{currentUser.isMemberOf('< 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 ||['uid:major_version'] <= 1
User doesn't belong to the external group'external') < 0
2 months ago manonlumeau NXDOC-1871: update Nuxeo sources retrieval
History: Created by manonlumeau

We'd love to hear your thoughts!

All fields required