As you learned in examples throughout the book, JavaScript is used in several different places across the Alfresco platform, particularly as one option for controller logic in web scripts. This section starts with a listing of the out of the box root JavaScript objects available to all scripts (except where noted), and then provides details for the rest of the JavaScript API.
The root objects available to your scripts are either utility objects or entry points into different areas of the JavaScript API. This section lists the root objects available and notes where further APIs exist. API details are provided in the next section, "JavaScript API".
Root Object |
Description |
---|---|
Entry point into the Actions API. Used to retrieve the list of actions configured in the repository or as a factory to retrieve an instance of an action. | |
|
Available when the script is run as a web script controller. Contains the arguments passed to the script. |
|
Entry point into the AVM API. Used to retrieve a list of all AVM stores, to search for a store based on ID, or to search for a specific node. |
|
Available when the script is run as a web script controller. The cache object is used to dynamically modify the cache settings for a web script. |
|
Entry point into the Classification API. Used to get and create root categories, or to get all category nodes for a classification. |
|
|
|
Utility object for copying nodes between the DM and AVM store (and vice-versa). |
|
|
|
Utility object for logging messages to the console. |
|
Available when the script is run as a web script controller. The associative array used to pass data to the view. |
|
Entry point into the People API, which is used to work with people and groups. |
|
|
|
|
Entry point into the Search API, which can be used to execute Lucene searches, XPath searches, saved searches, and searches based on node reference. | |
|
Used to retrieve the ticket for the current user executing the script. |
|
|
|
Available when the script is run as a web script controller. Used to set the response code, error message, and redirect flag. |
|
|
|
A generic utility object with commonly used functions. |
|
Available in Labs only, this is the entry point into the Workflow API. It is used to get tasks, workflow definitions, and workflow instances. It can also be used to create workflow packages. |
The classes that implement the JavaScript root objects are in org.alfresco.repo.jscript
. Much of the information in the tables within this section has been taken directly from the Alfresco Javadoc comments for the classes in that package.
Note
In this section, method names are listed as they appear in the underlying Java class. For getters and setters, this means the "get" or "set" is shown even though it is typically dropped in JavaScript. For example, document.tags
and document.getTags()
are equivalent.
This section lists general utility classes or classes that are used across multiple APIs, such as ScriptNode
.
Function |
Description |
Return value |
---|---|---|
|
Gets the |
|
Gets the source |
| |
|
Gets the target |
|
|
Gets the type of the association. |
String containing the |
Function |
Description |
Return value |
---|---|---|
Gets the child node on the target end of this association. |
| |
|
Gets the |
|
|
Gets the name of the association. |
String containing the |
|
Gets the parent node. |
|
|
Gets the type of the association. |
String containing the |
Determines whether or not this is the primary association for this node. |
True if this is the primary association, otherwise false. |
Function |
Description |
Return value |
---|---|---|
Retrieves a |
| |
|
Pads a string with zeros ("0") to the desired length. |
Padded String. |
Converts a String to a boolean. |
Boolean value. |
Function |
Description |
Return value |
---|---|---|
Determines if the web script can have its response placed in a public cache. |
True if the content is public, false if it is not. | |
|
Determines whether or not the cache should re-validate to make sure it is picking up the latest version of the web script response. |
True if cache should revalidate, false if it does not have to revalidate. |
|
Determines if the web script response should never be cached. |
True if the response should never be cached, false if it is OK to cache. |
|
Sets the |
Void |
|
Sets the |
Void |
|
Sets the |
Void |
Function |
Description |
Return value |
---|---|---|
Performs a copy of a source node to the specified parent destination node. The name will be applied to the destination node copy. Inter-store copy operations between Workspace and AVM and visa-versa are supported. |
|
Function |
Description |
Return value |
---|---|---|
|
Gets the status code for the web script's response. |
Code as an |
|
Sets the status code for the web script's response. |
Void |
|
Gets the description of the status code. |
String representing the status code description. |
Gets the short name of the status code. |
String representing the short name of the status code. | |
|
Gets the exception that's been set on this status object. |
Throwable representing the exception. |
|
Gets the location. |
String representing the location. |
|
Sets the location. |
Void |
|
Gets the web script status message. |
String representing the status message. |
|
Sets the web script status message. |
Void |
|
Gets the redirect flag. |
Boolean representing the redirect flag. |
|
Sets the redirect flag. |
Void |
Sets the exception. |
Void |
The AVM API is used for working with objects in the AVM store, which is currently only used by Alfresco's WCM functionality:
Function |
Description |
Return value |
---|---|---|
|
Gets the preview URL for the given |
String containing the URL. |
|
Gets the list of modified items for the specified user sandbox for a specific webapp as compared against the staging store in the store specified by the store ID. |
List of AVMNodes. |
|
Return an AVM Node for the fully qualified path. |
AVMNode of the matching node. |
|
Returns an AVM store object for the specified store name |
|
|
Returns an AVM Node representing the public store root folder. |
AVMNode of the root folder. |
|
Gets the staging store name for the given store ID. |
String containing the name. |
Gets a list of AVM stores in the repository. |
| |
|
Gets the Sandbox Store name for the given store ID and username. |
String containing the name. |
|
Gets the folder path to the webapps folder. |
String containing the path. |
|
Gets the preview URL for the web site managed in the store represented by the store ID. |
String containing the URL. |
|
Gets the preview URL for the user sandbox for the store and username specified. |
String containing the URL. |
Function |
Description |
Return value |
---|---|---|
|
Copies this node into a new parent destination. |
ScriptNode representing the copy of this node |
| Gets the list of aspects applied to this node. | List of QNames. |
| Gets the name property of the node. | String representing the name. |
| Determines whether or not the current user can make a change to the node either because the node is not locked or the node is locked and the user is the lock owner or a Content Manager. | True if the user can make a change, false if they cannot. |
| Determines whether or not this node is a directory. | True if it is a directory, false if it is not. |
| Determines whether or not this node is a file. | True if it is a file, false if it is not. |
| Determines whether or not this node is locked. | True if it is locked, false if it is not. |
| Determines if this node is locked and the current user is the lock owner. | True if the node is locked and the user is the lock owner, otherwise false. |
| Determines if this node is locked and the current user is the lock owner. | True if the node is locked and the user is the lock owner, otherwise false. |
| Moves this node to the specified destination. | True if the move is successful, false if it is not. |
| Gets the path to this node's parent. | String representing the path. |
| Gets the full AVM path to this node. | String representing the path. |
| Renames this node to the new name specified. | True if the rename is successful, false if it is not. |
| Gets the Qname type of the node. | String representing the type. |
| Gets the version of the node. | Version number of the node as an integer. |
Function |
Description |
Return value |
---|---|---|
|
Gets the store's creation date. |
Date the store was created. |
Gets the user who created the store. |
String representing the store creator. | |
|
Gets the store's ID. |
String representing the store ID. |
|
Looks up a node in the store; the path is assumed to be related to the webapps folder root. Therefore a valid path would be |ROOT/WEB-INF|lib|web.xml. |
|
|
Gets the store's name. |
String representing the name of the store. |
|
Gets the store's root node. |
AVMNode representing the root node. |
|
Executes a Lucene query against this store and returns the results. |
|
The Classification API is used for working with categories.
Function |
Description |
Return value |
---|---|---|
|
Gets all the aspects that define this classification. |
String array containing a list of aspect names. |
|
Creates a root category for this classification. |
Void |
Gets all category nodes for this classification. |
| |
|
Gets categories with the most number of objects. The number of categories returned is specified in |
|
|
Gets all root categories for this classification. |
|
Function |
Description |
Return value |
---|---|---|
|
Gets all of the members of a category. |
An array of |
Creates a new subcategory. |
| |
|
Gets the immediate members of a category. |
Array of |
|
Gets the immediate members and subcategories. |
Array of |
|
Gets the immediate subcategories. |
Array of |
|
Gets the members and subcategories for this category. |
Array of |
|
Removes this category. |
Void |
Gets the subcategories for this category. |
Array of |
The People API is for working with people and groups:
Function |
Description |
Return value |
---|---|---|
Adds an authority (a user or group) to a group container as a new child. |
Void | |
|
Creates a new root-level group (or a subgroup if a parent is specified) with the specified unique name (do not use the "GROUP_" prefix). |
|
|
Creates a person with a generated username. |
|
|
Deletes the specified group. |
Void |
|
Deletes the specified person object. |
Void |
|
Enables the specified user account. |
Void |
|
Gets the authorities this authority contains, optionally recursing into subauthorities. |
Array of Objects representing the contained authorities. |
|
Gets the groups that contain the specified authority. |
|
Gets the group specified. |
| |
|
Gets the people that belong to the specified group and, optionally, any sub-groups of the specified group. |
|
|
Gets all the people in the repository, optionally filtered by a query string. |
|
|
Gets the person given the specified username. |
|
|
Removes a person or group from the specified group. |
Void |
The Presence API can be used to determine whether or not someone is online according to their preferred presence provider:
The Search API is for executing queries, including saved searches: