Alfresco JavaScript API
Alfresco JavaScript API
com)
Home > Alfresco Community Edition 5.1 > Developer guide > API guide > Reference > JavaScript API
JavaScript API
The Repository JavaScript API lets you develop JavaScript (ECMAScript) 1.6 compatible files to access, modify, and create Alfresco repository
objects such as nodes, aspects, and properties.
Use the JavaScript API for web scripts that execute JavaScript in the repository.
Find nodes
Perform searches
Walk node hierarchies
Modify the value of properties, aspects, and associations
Transform and manipulate content
Create groups, people, and modify permissions
Create new files, folders, or nodes
Copy, move, and delete nodes
Create, modify, and remove child and target associations between nodes
Include or import other scripts
About script files [1] Script files are generally located either on the classpath (for example,
./tomcat/shared/classes/alfresco/extension/templates/webscripts), or in a repository store (for example, the default repository in Company
Home/Data Dictionary/Scripts)
Root objects [2] The JavaScript API provides a number of root objects which are available from your JavaScript code.
Scripting API [3] The Alfresco JavaScript API provides a rich set of scriptable Java objects.
Services API [4] The Alfresco JavaScript Services API provides an interface to core Alfresco services that can be accessed from web
scripts.
You can directly access scripts in the repository location using a URL with the appropriate read permissions on the script document. You can
import scripts on the classpath into other scripts but you cannot execute them directly in the Alfresco web client.
Importing scripts
This feature allows you to build libraries of scripts for use by other scripts at runtime. The syntax to import the scripts is specific to Alfresco and
is not a feature of standard JavaScript. For example, the <script src='...'> syntax, as supported by most web browsers, is not part of standard
ECMA JavaScript and will not work in Alfresco.
The syntax to import other scripts is very strict and you must follow it exactly; otherwise, the import can fail. Import directives must be the first
lines in the JavaScript file. This means that no code or comments are allowed above those lines, and the usual JavaScript code and comments
appear after the import lines. Only the following syntax variants are supported:
<import resource="workspace://SpacesStore/6f73de1b‐d3b4‐11db‐80cb‐112e6c2ea048">
<import resource="classpath:alfresco/extension/[Link]">
Root objects
The JavaScript API provides a number of root objects which are available from your JavaScript code.
The root objects have various types, depending on which part of the system they expose. For example, the common Alfresco repository
concepts, such as the Company Home folder and the logged in user, are represented through objects of type ScriptNode. These objects support
the full range of properties and objectoriented API of the ScriptNode class.
Depending on the context in which the script is invoked, other types of root object are available that represent aspects of the system such as
server details, user information, request headers and parameters passed to the script. Further, a variety of Alfresco services are accessible
from your JavaScript code, each of these services has a corresponding root object, on which properties can be accessed and a variety of
methods called as dictated by the service's API.
See also Web script reference guide, which covers root objects in more detail. [7]
The root objects available to your JavaScript code will depend on the context in which the code is invoked. Different contexts will have access
to a different set of root objects. There are several contexts to be considered:
Web scripts
Surf
Rules/actions
Workflow
Share
This information looks at the most commonly used root objects. More specialized root objects are described in more detail in the relevant
sections of this documentation.
Further information on root objects provided by services and the exposed APIs can be found in the Services API reference [8].
Root
Object Type in Script Runtime Description
companyhome [Link] The company home ScriptNode. See ScriptNode API for properties and methods.
document [Link] The current node ScriptNode (if any)
person [Link] The ScriptNode representing the Person object of the currently authenticated user. See
ScriptNode API for properties and methods.
roothome [Link] The store root ScriptNode. The repository root folder. See ScriptNode API for properties
and methods.
script [Link] The ScriptNode representing the script object itself. This is only available if the script is
loaded from the Java classpath.
space [Link] The primary parent ScriptNode for the current node (ScriptNode). For a script executing
from a rule, the space object is the space in which the rule resides. If the rule is inherited,
this might not be the expected space.
userhome [Link] The current user's Home Space ScriptNode. See ScriptNode API for properties and
methods.
Scripting API
The Alfresco JavaScript API provides a rich set of scriptable Java objects.
Many rootscope objects are provided by default, such as access to the user home folder, company home folder, WCM web projects, search,
People API, and logging functionality. You can also configure additional rootscope objects for use with your own scripts.
ScriptNode API [10] In JavaScript code various parts of the underlying system can be conveniently exposed as objects of type ScriptNode.
For example, the companyhome, userhome, document, space, and person objects are best represented as objects of type ScriptNode. The
ScriptNode API provides access to properties and methods for manipulating this type of object.
Actions API [11] The actions API provides a root level actions object that allows invocation of Alfresco actions registered with the
repository.
Classification API [12] The Classification API has two parts: manipulating classifications, and manipulating the categories they contain.
Logging API [13] A root level logger object provides a number of methods to help debug scripts.
People API [14] The People API provides access to Alfresco people and groups.
ScriptAction API [15] A ScriptAction represents an Alfresco action registered within the repository.
Search API [16] The Search API provides direct access to repository level search results and Saved Search results through the search root
scope object.
Session API [17] A root level session object is provided to access the servelt web session.
SessionTicket API [18] A root level sessionticket object is provided to access the current logged in user session ticket as a string value.
Utility methods [19] A root level utils object is provided as a library of helper methods that are missing from generic JavaScript.
ScriptNode API
In JavaScript code various parts of the underlying system can be conveniently exposed as objects of type ScriptNode. For example, the
companyhome, userhome, document, space, and person objects are best represented as objects of type ScriptNode. The ScriptNode API provides
access to properties and methods for manipulating this type of object.
Properties
The following properties are available to use within scripts:
The following code snippet obtains a list of workflow objects for the file TEST_FILE_0.TXT:
aspects Readonly A readonly array of the fully qualified QName strings applied to the node
aspectsSet Readonly A list of aspects applied to this node
aspectsShort Readonly An array of aspects as short prefix qnames applied to this node
associations Readonly The same as assocs
assocs Readonly A readonly associative array of the target associations of the node. Each named entry in the array contains
an array of the script node objects on the end of the association.
Example: [Link]["cm:translations"][0]
Example: [Link]["fm:discussion"][0]
Example: [Link][0]
content Readwrite The content string for this node from the default content property (ContentModel.PROP_CONTENT).
displayPath Readonly A readonly display path to this node
downloadUrl Readonly For a content document this is a readonly string representing the download (as attachment) URL for the
content. For a container node this would be an empty string.
hasChildren Readonly True if the node has children
icon16 Readonly A readonly small icon image for this node
icon32 Readonly A readonly large icon image for this node
id Readonly The GUID for the node
isCategory Readonly Returns true if this node is a category, or false otherwise
isContainer Readonly Returns true if the node is a folder node, or false otherwise
isDocument Readonly Returns true if this node is a document, or false otherwise
isLinkToContainer Readonly Returns true if this node is a link to a container, or false otherwise
isLinkToDocument Readonly Returns true if this node is a link to a document, or false otherwise
isLocked Readonly Returns true if the node is locked, or false otherwise. Once a node is checked out it becomes locked.
mimetype Readwrite A read/write value representing the MIME type of the content
name Readwrite Shortcut access to the cm:name property. Can be read and written to.
nodeRef Readonly The NodeRef corresponding to this node
parent Readonly Primary parent node. This will be null if this is the root node.
parentAssociations Readonly Same as parentAssocs
parentAssocs Readonly A readonly associative array of the parent associations of the node. Each named entry in the array contains
an array of the script node objects on the end of the association.
Example: [Link]["cm:contains"][0]
Example: [Link]["name"]
Example: [Link]
Example: [Link]["cm:translations"][0]
getPropertyNames [31]getPropertyNames(useShortQNames) returns all the property names defined for this node as an array.
getTypePropertyNames [32]getTypePropertyNames returns all the property names defined for this node's type as an array.
childByNamePath [33]childByNamePath(path) performs a pathbased query based on the name property of the nodes.
childrenByXPath [34]childrenByXPath(xpath) performs an XPathbased query relative to the current node.
childFileFolders [35] The childFileFolders methods are used to obtain an array of child files and folders for the node.
isScriptContent [36]isScriptContent(obj) determines whether the supplied node property value is a ScriptContentData object.
hasAspect [37]hasAspect(type) returns true if an aspect was applied to the node.
getChildAssocsByType [38]getChildAssocsByType(String type) returns an array of the associations from the referenced node that match a
specific object type.
isSubType [39]isSubType(type) determines if this node is a subtype of the specified type.
exists [40]exists() checks whether the node exists in the repository.
reset [41]reset() resets the node cached state of a node.
toJSON [42]toJSON() returns the JSON representation of this node.
Security/Permissions API [43] The Security ScriptNode API features several methods and properties related to permissions of nodes in
the repository.
Ownership API [44] The Ownership ScriptNode API provides methods to get, set and take ownership of a node.
Modifying and creating API [45] Most of the available ScriptNode API return readonly values, however the Scripting API also supports
writable objects and access to Alfresco repository services.
Check in/check out API [46] The check in/check out ScriptNode API features methods for check out, check in, and cancelling check out of
working copies.
Versions API [47] The Versions ScriptNode API provides several methods and properties for managing and retrieving the versions of a
document.
Content API [48] The Content API provides several properties to manipulate node content directly. The content can also be manipulated
using the ScriptContentData API.
ScriptContentData API [49] The ScriptContentData API provides several methods and properties related to node properties of type
d:content; for example, [Link].
Transformation API [50] The Transformation API provides document, image, and FreeMarker template processing services in Alfresco.
Thumbnail API [51] A thumbnail is a transformation of content into a specified destination MIME type. This is most commonly an image of
a particular size, but can also be other things, for example, a Flash rendition. The ScriptNode class provides several methods for
generating and handling thumbnails.
Tagging API [52] A tag is a nonhierarchical keyword or term assigned to a piece of information.
Parameters
useShortQNames
If true shortform qnames will be returned, else longform.
Returns
Returns an array of property names for this node type and optionally parent properties.
Example
var props = [Link](true);
getTypePropertyNames
getTypePropertyNames returns all the property names defined for this node's type as an array.
getTypePropertyNames
getTypePropertyNames(useShortQNames) Returns all the property names defined for this node's type as an array.
Returns
Returns an array of property names for this node's type. Short qnames are returned.
Example
var props = [Link]();
getTypePropertyNames (boolean)
getTypePropertyNames(useShortQNames) Return all the property names defined for this node's type as an array.
Parameters
useShortQNames
If true shortform qnames will be returned, else longform.
Returns
Example
var props = [Link](false); // return long form qnames
childByNamePath
childByNamePath(path) performs a pathbased query based on the name property of the nodes.
Parameters
path
The path to the node.
Returns
Returns a node found at the specified path relative to the current node. If this is not found, null is returned.
Example
var testingFolder =[Link]("QA/Performance/Testing");
childrenByXPath
childrenByXPath(xpath) performs an XPathbased query relative to the current node.
Parameters
xpath
XPath query to select nodes.
Returns
Returns an array of the nodes found. If no results are matched, returns an empty array.
Example
var nodes = [Link]("*[@cm:name='Finance Documents']/*");
childFileFolders
The childFileFolders methods are used to obtain an array of child files and folders for the node.
Parent topic: ScriptNode API [10]
childFileFolders()
Returns
Returns a JavaScript array of child file and folder nodes for the node. It automatically retrieves all subtypes of cm:content and cm:folder, and
removes system type folders from the results.
Example
childFileFolders(files, folders)
Returns an array of child files and folders for the node, and as modified by parameters.
Parameters
files
A boolean value which if set to true specifies that files extending from cm:content should be returned.
folders
A boolean value which if set to true specifies that folders extending from cm:folder should be returned, ignoring subtypes of
cm:systemfolder.
Returns
Returns a JavaScript array of child file and folder nodes for the node. It automatically retrieves all subtypes of cm:content and cm:folder, and
removes system type folders from the results.
Example
Parameters
files
A boolean value which if set to true specifies that files extending from cm:content should be returned.
folders
A boolean value which if set to true specifies that folders extending from cm:folder should be returned, ignoring subtypes of
cm:systemfolder.
ignoreTypes
Can be set to filter nodes of the specified type or types from the results returned. The type is specified in either long or short QName
string form, as a single string or as an array of strings to filter multiple types.
Returns
Returns a JavaScript array of child file and folder nodes for the node. It automatically retrieves all subtypes of cm:content and cm:folder, and
removes system type folders from the results.
Example
var nodes = [Link](true, true, "cm:folder"); // ignore folders
var nodes = [Link](true, true, ["cm:folder", "st:sites"]); // ignores folders and sites
Returns a ScriptPagingNode object containing child files and folders for the node, as well as information to control paging of results. Parameters
can be used to filter results. It is also possible to limit the number of nodes returned in the results.
CAUTION:
This method is deprecated in version 4.0.
Parameters
files
A boolean value which if set to true specifies that files extending from cm:content should be returned.
folders
A boolean value which if set to true specifies that folders extending from cm:folder should be returned, ignoring subtypes of
cm:systemfolder.
ignoreTypes
Can be set to filter nodes of the specified type or types from the results returned. The type is specified in either long or short QName
string form, as a single string or as an array of strings to filter multiple types.
maxItems
An integer value which sets the maximum number of results to return.
Returns
Returns a ScriptPagingNode object. The results are limited to the number specified by maxItems.
Example
var nodeNames = new Array();
var nodes = null;
var maxItems = 10;
nodes = [Link]();
Parameters
files
A boolean value which if set to true specifies that files extending from cm:content should be returned.
folders
A boolean value which if set to true specifies that folders extending from cm:folder should be returned, ignoring subtypes of
cm:systemfolder.
ignoreTypes
Can be set to filter nodes of the specified type or types from the results returned. The type is specified in either long or short QName
string form, as a single string or as an array of strings to filter multiple types.
skipOffset
Number of items to skip. For example 0, or number of pages to skip * size of page.
maxItems
An integer value which sets the maximum number of items, the size of the page.
requestTotalCountMax
Request total count (up to a given max total count) Note, if set to 0 then total count is not requested and the query might be able to
optimise/cutoff for max items.
sortProp
Optional sort property as a prefix QName string, for example cm:name. Also supports special content cases such as cm:[Link] and
cm:[Link].
sortAsc
A boolean value. If true nodes will be sorted in ascending order, if false nodes will be sorted in descending order.
queryExecutionId
If paging then can pass back the previous query execution (as a hint for possible query optimization). Note this parameter is not used, it is
reserved for future use.
Returns
Returns a ScriptPagingNode containing child file and folder nodes for the node. It automatically retrieves all subtypes of cm:content and
cm:folder, and removes system type folders from the results.
Example
var queryExecutionId = null; // reserved for future use
var results;
var nodeNames = new Array(); // just store file names in a list
var resultsTrimmed = false;
var nodes = null;
nodes = [Link]();
isScriptContent
isScriptContent(obj) determines whether the supplied node property value is a ScriptContentData object.
Parameters
obj
Node property value
Returns
Boolean. Returns true if the supplied node property value is a ScriptContentData object; otherwise, it returns false.
hasAspect
hasAspect(type) returns true if an aspect was applied to the node.
Parameters
type
The type of aspect whose presence will be checked for. Examples include cm:versionable and cm:templatable.
Returns
Boolean
Example
var isTemplatable = [Link]("cm:templatable");
...
var node = [Link]("TEST_FILE_0.TXT");
[Link] = [Link]("cm:versionable");
getChildAssocsByType
getChildAssocsByType(String type) returns an array of the associations from the referenced node that match a specific object type.
Parameters
type
A string representing the specific object type.
Returns
Returns the aspects applied to this node as an array of short prefix qname strings.
Example
var assoc = [Link]("cm:folder")[0];
isSubType
isSubType(type) determines if this node is a subtype of the specified type.
Parameters
type
The qname type to test this object against (fully qualified or shortname form).
Returns
Returns true if this node is a subtype of the specified type (or itself of that type).
exists
exists() checks whether the node exists in the repository.
Returns
Returns a boolean, true if the node exists, false otherwise.
Example
if ([Link]()){
...
}
reset
reset() resets the node cached state of a node.
Example
The following would reset the cached state of the node:
[Link]();
toJSON
toJSON()returns the JSON representation of this node.
Parent topic: ScriptNode API [10]
toJSON
toJSON() returns the JSON representation of this node. Longform QNames are used in the result.
Returns
toJSON
toJSON(boolean useShortQNames) returns the JSON representation of this node. Shortform QNames are used in the result.
Parameters
boolean useShortQNames
If true, shortform QNames will be returned, else longform QNames will be returned.
Returns
Security/Permissions API
The Security ScriptNode API features several methods and properties related to permissions of nodes in the repository.
The Security API provides a wide range of methods for setting and getting permissions on nodes. It is good practice to check for the
appropriate user permissions on a node before accessing or modifying it.
Properties
permissions
Array of permissions applied to this node, including inherited permissions.
directPermissions
Array of permissions applied to this node, excluding inherited permissions.
fullPermissions
Array of all permissions applied to this node, including inherited permissions.
settablePermissions
Array of settable permissions for this node.
hasPermission [53]hasPermission(permission) checks if a user has the specified permission on a node.
inheritsPermissions [54]inheritsPermissions() indicates whether the node inherits permissions.
setInheritsPermissions [55]setInheritsPermissions(inherit) indicates that the node should inherit permissions from the parent node when
set to true. Set to false to break the inheritance chain.
setPermission [56] The setPermission methods apply permissions to nodes.
removePermission [57] The removePermission methods remove permissions for users from a node.
getPermissions [58]getPermissions() returns an array of permissions attached to a node.
hasPermission
hasPermission(permission) checks if a user has the specified permission on a node.
The default permissions are in [Link]. The most commonly used permission checks are:
Read
Write
Delete
AddChildren
CreateChildren
Parameters
permission
The specified permission
Returns
Returns true if the user has the specified permission on the node.
inheritsPermissions
inheritsPermissions() indicates whether the node inherits permissions.
Returns
Returns true if the node currently inherits its permissions from the parent space, and returns false to indicate the permissions are set
specifically on the node.
setInheritsPermissions
setInheritsPermissions(inherit) indicates that the node should inherit permissions from the parent node when set to true. Set to false to break
the inheritance chain.
Parameters
inherit
True to indicate the node inherits from its parent. False, indicates the node should not inherit permissions from the parent node.
setPermission
The setPermission methods apply permissions to nodes.
Parent topic: Security/Permissions API [43]
setPermission(permission)
setPermission(permission)
permission
The permission to apply to the node.
setPermission(permission, authority)
setPermission(permission, authority)
This method applies a permission for the specified authority (for example, a user name or group) to the node.
Note that the method does not check for the presence of the specified authority, so the method will not fail if a nonexistent user is specified.
The existence of a user or group should be checked for in preceding code for additional robustness.
Parameters
permission
The permission to apply to the node.
authority
The authority (user, group) for which the permission will be applied.
Example
var node = [Link]("TEST_FILE_0.TXT");
[Link]("Read", "[Link]");
[Link]("Delete", "Admin");
[Link]("Write", "GROUP_EVERYONE");
[Link]("Delete", "GROUP_ALFRESCO_ADMINISTRATORS");
[Link]("Delete", "[Link]"); // user doesn't exist!
[Link] = [Link]();
ALLOWED;[Link];Delete
ALLOWED;Admin;Delete
ALLOWED;GROUP_EVERYONE;Write
ALLOWED;GROUP_ALFRESCO_ADMINISTRATORS;Delete
removePermission
The removePermission methods remove permissions for users from a node.
Parent topic: Security/Permissions API [43]
removePermission(permission)
Parameters
permission
The permission to remove.
removePermission(permission, authority)
removePermission(permission, authority) removes a permission for the specified authority (for example, a user name or group) from the node.
Parameters
permission
The permission to remove.
authority
The authority, typically a user name or group, to remove the permission for.
Example
var node = [Link]("TEST_FILE_0.TXT");
[Link]("Read", "[Link]");
[Link]("Delete", "Admin");
[Link]("Write", "GROUP_EVERYONE");
[Link]("Delete", "GROUP_ALFRESCO_ADMINISTRATORS");
//...
[Link]("Read", "[Link]");
[Link] = [Link]();
ALLOWED;Admin;Delete
ALLOWED;GROUP_EVERYONE;Write
ALLOWED;GROUP_ALFRESCO_ADMINISTRATORS;Delete
getPermissions
getPermissions() returns an array of permissions attached to a node.
Returns
An array of permissions applied to this node, including inherited permissions.
Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION. An example is ALLOWED;GROUP_EVERYONE;Consumer. The string
can then be tokenized on the ';' character.
Example
var node = [Link]("TEST_FILE_0.TXT");
[Link] = [Link]();
Ownership API
The Ownership ScriptNode API provides methods to get, set and take ownership of a node.
Properties
owner
The owner property of the node (as a UID)
takeOwnership [59]takeOwnership() this method results in the authenticated user running the script to take ownership of the node.
takeOwnership
takeOwnership() this method results in the authenticated user running the script to take ownership of the node.
Example
If running the script while authenticated as admin, the following code would result in admin being returned as the owner.
//...
[Link] = [Link]();
The ScriptNode object lets you modify and add properties, add aspects, create new files, folder, and custom type nodes, and update and set the
text content stream for a node. You can also delete nodes, transform content, execute templates, and modify the associations for a node.
Remember: JavaScript objects are different to native repository Java objects. Property values in the repository must be the correct object type
as defined in the Data Dictionary and exposed by the content model. This means that a string property value expects a Java string, and a multi
valued property expects a list. The Alfresco JavaScript API converts most object types between JavaScript and Java for you such as Array (for
a multivalue property), numbers, dates, Boolean, and strings. The conversion code handles all common type conversions and recursive lists of
those types.
Type Description
properties Property array (can be modified for updating or adding new properties)
Example:
The [Link]() API call is required to persist the property modifications. All other modifications made
using the API, such as content or adding aspects, take immediate effect.
createFolder [60] The createFolder methods create a new folder as a child of the current node.
createFile [61] The createFile methods create a new file as a child of the current node. Once created the file should have content set
using the content property.
createNode [62] The createNode methods are used to create new nodes.
addNode [63] The addNode(node) method adds an existing node as a child of this node.
removeNode [64]removeNode(node) removes all parentchild relationships between two nodes.
createAssociation [65]createAssociation(target, assocType) creates a new target association to the specified node with the given
association type QName.
removeAssociation [66]removeAssociation(target, assocType) removes the association to the specified node with the given association
type QName.
remove [67]remove() this method deletes the node.
copy [68] The copy
move [69]move moves the node to the specified destination.
addAspect [70] The addAspect methods are used to add new aspects to nodes.
removeAspect [71]removeAspect(aspect) removes the specified aspect from the node.
specializeType [72]specializeType(type) specializes the type of a node.
revert [73]revert reverts node to the specified version.
save [74]save() persists the modified properties of this node.
createFolder
The createFolder methods create a new folder as a child of the current node.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] first.
createFolder(name)
createFolder(name) this method creates a new folder (cm:folder) node with the specified name as a child of this node.
Parameters
name
The folder name
Returns
Returns the new node as the result of the function or returns null if the creation fails.
Example
var myfolder = [Link]("New Folder");
createFolder(name, type)
createFolder(name, type) this method creates a new folder (cm:folder) node with the specified name and type as a child of this node.
Parameters
name
The folder name
type
The type of the folder to create. If null it defaults to type ContentModel.TYPE_FOLDER. Examples of folder types include cm:systemfolder,
cm:folder, st:site, and fm:forum.
Returns
Returns the new node as the result of the function or returns null if the creation fails.
Example
createFile
The createFile methods create a new file as a child of the current node. Once created the file should have content set using the content
property.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] on the node first.
createFile(name)
createFile(name) this method creates a new file node of type cm:content with the specified name. The node is created as a child of the current
node.
Parameters
name
The name of the file to create
Returns
Returns the newly created node as the result of the function, or returns null if the creation failed. Alfresco puts the file MIME type of the content
(there is no MIME type with the createNode method).
Example
createFile(name, type)
createFile(name) this method creates a new file node of type cm:content with the specified name. The node is created as a child of the current
node.
Parameters
name
The name of the file to create
type
The type of file to create. If null will create ContentModel.TYPE_CONTENT.
Returns
Returns the newly created node as the result of the function, or returns null if the creation failed. Alfresco puts the file MIME type of the content
(there is no MIME type with the createNode method).
Example
var myfile = [Link]("[Link]", "cm:content");
createNode
The createNode methods are used to create new nodes.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] first.
createNode(name,type)
This method creates a new node of the specified type (a QName in either full or short form).
Parameters
name
The node name. Name of the node to create (can be null for a node without a 'cm:name' property).
type
The node type. QName type (fully qualified or short form such as 'cm:content').
Returns
Example
This method creates a new node of the specified type as a child of the current node with the given child association type.
Parameters
name
The node name. Name of the node to create (can be null for a node without a 'cm:name' property).
type
The node type. QName type (fully qualified or short form such as 'cm:content').
assocType
The QName of the child association type (fully qualified or short form, for example, 'cm:contains')
Example
var node = [Link]("My Discussion", "fm:forum", "fm:discussion");
This method creates a new node as a child of the current node with the specified properties.
Parameters
name
The node name. Name of the node to create (can be null for a node without a 'cm:name' property).
type
The node type. QName type (fully qualified or short form such as 'cm:content').
properties
An associative array of the properties to be added to the node upon creation. This is useful when a type requires the setting of mandatory
properties.
Returns
Example
var node = [Link]("Sites/test");
var forumName = "My Forum";
var properties = new Array();
properties['cm:title'] = "The forum title";
properties['cm:description'] = "The forum description";
var forum = [Link](forumName, "fm:forum", properties);
createNode(name, type, properties, assocType)
This method creates a new node as a child of the current node. The node contains the specified child association name with the specified
properties with that child association type.
Parameters
name
The node name. Name of the node to create (can be null for a node without a 'cm:name' property).
type
The node type. QName type (fully qualified or short form such as 'cm:content').
properties
An associative array of the properties to be added to the node upon creation.
assocType
The QName QName of the child association type (fully qualified or short form, for example, 'cm:contains').
This method creates a new node as a child of the current node. The node contains the specified child association name with the specified
properties, and the given child association type and name.
Parameters
name
The node name. Name of the node to create (can be null for a node without a 'cm:name' property).
type
The node type. QName type (fully qualified or short form such as 'cm:content').
properties
An associative array of the properties to be added to the node upon creation
assocType
The QName of the child association type (fully qualified or short form, for example, 'cm:contains').
assocName
The QName of the child association name (fully qualified or short form, for example, 'fm:discussion').
addNode
The addNode(node) method adds an existing node as a child of this node.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] first.
Parameters
node
The node to add as a child of the current node.
Returns
void
Example
var dir = [Link]("SUB_FOLDER", "cm:folder");
[Link](node);
[Link] = node;
The child node will be cascade deleted if one of the associations was the primary association, that is, the one with which the child node was
created.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] first.
Parameters
node
The node to be removed.
Example
var dir = [Link]("SUB_FOLDER");
var node = [Link]("SUPER_FILE.TXT");
[Link](node);
createAssociation
createAssociation(target, assocType) creates a new target association to the specified node with the given association type QName.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] first.
Parameters
target
Destination node for the association
assocType
Association type qname (short form or fully qualified)
Returns
The new association.
removeAssociation
removeAssociation(target, assocType) removes the association to the specified node with the given association type QName.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] first.
Parameters
target
Destination node on the end of the association
assocType
Association type qname (short form or fully qualified)
remove
remove() this method deletes the node.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] first.
Returns
Returns true on success, or false otherwise.
Example
Any variable or references to the ScriptNode should be discarded. For example:
[Link]();
Parent topic: Modifying and creating API [45]
copy
The copy
methods are used to copy nodes to specified destination nodes.
copy(destination)
Parameters
destination
The destination node
Returns
Returns the newly copied ScriptNode instance on success, or null if the copy fails.
Example
copy(destination, deepCopy)
This method copies the node to the specified destination node. It copies all child nodes of the source if the deepCopy argument is true.
Otherwise, it only copies the source node itself.
Parameters
destination
The destination node
deepCopy
True for a deep copy, false otherwise.
Returns
Returns the newly copied ScriptNode instance on success, or null if the copy fails reason.
Example
move
movemoves the node to the specified destination.
Parent topic: Modifying and creating API [45]
move(destination)
move(destination) this method moves the node to the new parent destination.
Parameters
destination
The destination node.
Returns
Boolean
move(source, destination)
move(source, destination) this method moves the specified source node to the new parent destination.
Parameters
source
The source node.
destination
The destination node.
Returns
Boolean
addAspect
The addAspect methods are used to add new aspects to nodes.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] first.
addAspect(aspect)
This method adds a new aspect and properties to the node allowing mandatory aspect properties to be supplied when the new aspect is
applied.
Parameters
aspect
The aspect to add
Returns
True if the aspect was added successfully, false otherwise.
Example
[Link]("cm:translatable");
addAspect(aspect, properties)
This method adds a new aspect and properties to the node allowing mandatory aspect properties to be supplied when the new aspect is
applied.
Parameters
aspect
The aspect to add
properties
An associative array of QName keyed properties. Any mandatory properties for the aspect must be provided.
Returns
True if the aspect was added successfully, false otherwise.
Example
var props = new Array();
props["cm:template"] = [Link];
[Link]("cm:templatable", props);
removeAspect
removeAspect(aspect) removes the specified aspect from the node.
Note: Any unsaved property changes will be lost when this method is called. To preserve property changes call save() [75] first.
Parameters
aspect
The aspect type to remove
Returns
True if aspect removed, false otherwise.
specializeType
specializeType(type) specializes the type of a node.
Resets the type of the node. Can be called in order specialise a node to a subtype. This should be used with caution since calling it changes
the type of the node and thus implies a different set of aspects, properties and associations. It is the responsibility of the caller to ensure that
the node is in an approriate state after changing the type.
Parameters
type
The type name supplied must be a subtype of the current type as defined in the Data Dictionary
Returns
Boolean. Returns true on success, false otherwise.
revert
revertreverts node to the specified version.
Parent topic: Modifying and creating API [45]
revert(history, majorVersion, versionLabel) this method reverts the node to the specified version.
The node must have the cm:versionable aspect. The node will be checked out if required and will be checked in after the call. This method does
not attempt to perform a deep revert of associations.
Parameters
history
A revision history note.
majorVersion
If set to true the method will try to save the changes as a major version increment. If false will save as a minor version increment.
versionLabel
The version label to revert from.
Returns
ScriptNode
Returns the original node that was checked out if reverted, or null if the specified version does not exist.
revert(history, majorVersion, versionLabel, deep) revert this node to the specified version and potentially all child nodes.
The node must have the aspect cm:versionable. The node will be checked out if required, and checked in on completion of the call.
Parameters
history
A revision history note.
majorVersion
If set to true the method will try to save the changes as a major version increment. If false will save as a minor version increment.
versionLabel
The version label to revert from.
deep
If set to true the method will perform a deep revert. If set to false a deep revert will not be performed, and only the current node will be
reverted.
Returns
ScriptNode
Returns the original node that was checked out if reverted, or null if the specified version does not exist.
save
save() persists the modified properties of this node.
Example
var node = [Link]("TEST_FILE_1.TXT");
checkout
The checkout methods perform checkouts of versionable nodes.
Parent topic: Check in/check out API [46]
checkout ()
Returns
Example
var workingCopy;
var node = [Link]("TEST_FILE_1.TXT");
[Link](true, true);
if ([Link]){
workingCopy = [Link]();
[Link] = "Add some content.";
[Link]("Added some content.");
}
checkout(destination)
checkout(destination) this method performs a check out of the node to the specified destination.
Parameters
destination
Destination for the checked out document working copy node.
Returns
checkin
The checkin methods perform check in operations on working copy nodes.
Parent topic: Check in/check out API [46]
checkin()
checkin() this method performs a check in operation on a working copy node. It copies the current state of the working copy to the original node
(including any content updated in the working node). This method can only be called on a working copy node.
Returns
checkin(description)
checkin(description) this method performs a check in operation on a working copy node applying the specified version history note text.
Parameters
description
A version history note. A description of the change made.
Returns
Example
var workingCopy;
var node = [Link]("TEST_FILE_1.TXT");
[Link](true, true);
if ([Link]){
workingCopy = [Link]();
[Link] = "Add some content.";
[Link]("Added some content.");
}
checkin(description, majorVersion)
checkin(description, majorVersion) this method performs a check in operation on a working copy node.
It applies the specified version history note text and as a major or minor version increment as required.
Parameters
description
A version history note. A description of the change made.
majorVersion
True to save as a major version increment, false for minor version
Returns
The working copy is deleted and any changes made to it are lost.
Note: This method can only be called on a working copy node. Any reference to this working copy node should be discarded.
Returns
Returns the original node that was previously checked out.
Example
var workingCopy;
var node = [Link]("TEST_FILE_1.TXT");
[Link](true, true);
if ([Link]){
workingCopy = [Link]();
[Link] = "Add some content.";
// changed mind
node = [Link]();
checkoutForUpload
checkoutForUpload() performs a checkout of the node for upload.
Returns
Returns the resulting working copy node.
unlock
unlock()removes a lock on the node.
Parent topic: Check in/check out API [46]
Versions API
The Versions ScriptNode API provides several methods and properties for managing and retrieving the versions of a document.
Properties
isVersioned
A readonly Boolean property for determining if the document is versioned
versionHistory
A readonly property for listing all versions of the document in descending (version created) date order
Script Version Object [81] The Versions ScriptNode API provides methods that return ScriptVersion objects, for example, getVersion().
ScriptVersion objects have the following properties.
getVersion [82]getVersion(label) gets a specific version of a document identified by label.
createVersion [83]createVersion(history, major) this method creates a version snapshot of the current document.
ensureVersioningEnabled [84]ensureVersioningEnabled(autoVersion, autoVersionProps) ensures that this node has the cm:versionable
aspect applied to it, and that it has the initial version in the version store.
getVersionHistory [85]getVersionHistory() gets the version history for the current node.
Properties
createdDate
A readonly property representing the date at which the version was created
creator
A readonly property representing the user name of the person who created the version
label
A readonly property representing the version label
type
A readonly property representing the version type (MAJOR, MINOR)
description
A readonly property representing the description (history comment) of the version
nodeRef
A readonly property representing the node reference of the document that was versioned
node
A readonly property representing the node as it was versioned
getVersion
getVersion(label) gets a specific version of a document identified by label.
Parameters
label
The version label of the node to get.
Returns
A ScriptVersion object representing the version of this node requested.
Example
var version;
var createdDate;
var creator;
if ([Link]){
version = [Link]("1.0");
createdDate = [Link];
creator = [Link];
}
createVersion
createVersion(history, major) this method creates a version snapshot of the current document.
Parameters
history
Version history note. A description of the change made.
major
True to save as a major version increment, false for minor version.
Returns
Returns a ScriptVersion object for the new version of the document.
Calling this on a versioned node with a version store entry will have no effect. Calling this on a newly uploaded share node will have versioning
enabled for it.
Parameters
autoVersion
If set to true auto versioning will also be applied if the cm:versionable aspect is applied.
autoVersionProps
If set to true auto versioning of properties will also be applied, if the cm:versionable aspect is applied.
Returns
ScriptVersion
Example
var version;
var createdDate;
var creator;
[Link](true, true);
if ([Link]){
version = [Link]("1.0");
createdDate = [Link];
creator = [Link];
}
getVersionHistory
getVersionHistory() gets the version history for the current node.
Returns
Version history as a list of ScriptVersion objects.
Example
var versionHistory;
var revisionDates = new Array();
[Link](true, true);
if ([Link]){
versionHistory = [Link]();
Content API
The Content API provides several properties to manipulate node content directly. The content can also be manipulated using the
ScriptContentData API.
Properties
content
A read/write value that represents the content as a string
mimetype
A read/write value representing the MIME type of the content
size
A readonly long value that represents the size (in bytes) of the content
url
A readonly string representing the download URL for the content
downloadUrl
A readonly string representing the download (as attachment) URL for the content
webdavUrl
A readonly string representing the webdav URL for the content
ScriptContentData API
The ScriptContentData API provides several methods and properties related to node properties of type d:content; for example,
[Link].
Properties
content
A read/write value that represents the content as a string
mimetype
Guess and apply the MIME type to the content based on the file name
encoding
A read/write string value that represents the encoding of the content
size
A readonly long value that represents the size (in bytes) of the content
url
A readonly string representing the download URL for the content
downloadUrl
A readonly string representing the download (as attachment) URL for the content
write
write(content)copies the content from the specified ScriptContent.
Parent topic: ScriptContentData API [49]
write(content)
Parameters
content
The source ScriptContentData object.
Example
var sourceFilename = "TEST_FILE_1.TXT";
var destFilename = "TEST_FILE_2.TXT";
Parameters
content
The source ScriptContentData object.
applyMimetype
If set to true, the mimetype will be set from the mimetype of the source ScriptContentData object. If false, the mimetype of the target is
unchanged.
guessEncoding
If true the method will attempt to determine the encoding from the source content stream. If false, the encoding as set in the source
content object will be used.
Example
// use mimetype and encoding from source node
[Link]([Link], true, false);
write(inputStream)
Parameters
inputStream
The source inputStream.
Example
// use source node content stream
[Link]([Link]());
guessMimetype
guessMimetype(filename) guesses and applies the MIME type to the content based on the given file name.
Parameters
filename
The file name of the content
guessEncoding
guessEncoding() guesses and applies the encoding to the content based on the current content. It uses the ContentCharsetFinder service.
Parameters
none
getInputStream
getInputStream() returns the input stream for the underlying ScriptContentData object.
Parameters
none
Returns
Input stream of the underlying ScriptContentData object.
Parameters
none
Returns
The reader for the input stream of the underlying ScriptContentData object.
Transformation API
The Transformation API provides document, image, and FreeMarker template processing services in Alfresco.
transformDocument [91] The transformDocument methods use the document transformation services in Alfresco.
transformImage [92] The transformImage methods use the image transformation services in Alfresco.
processTemplate [93] The processTemplate methods use the FreeMarker template processing services in Alfresco.
transformDocument
The transformDocument methods use the document transformation services in Alfresco.
transformDocument(mimetype)
this method transforms a document to a new document MIME type format. It makes a copy of the document,
transformDocument(mimetype)
changes the extension to match the new MIME type, and applies the transformation.
Parameters
mimetype
The mimetype of the new document.
Returns
Returns the transformed document node if successful, or null if the transformation failed.
Example
transformDocument(mimetype, destination)
transformDocument(mimetype, destination) this method transforms a document to a new document MIME type format. It makes a copy of the
document in the specified destination folder, changes the extension to match the new MIME type, and applies the transformation.
Parameters
mimetype
The mimetype of the new document.
destination
The destination folder in which the new document will be placed.
Returns
Returns the transformed document node if successful, or null if the transformation failed.
Example
// transform document and place new document in destination folder
var node = [Link]("TEST_1.TXT");
var destDir = [Link]("TRANSFORMED_DOCS");
transformImage
The transformImage methods use the image transformation services in Alfresco.
Note: To use these services, the ImageMagick components must be installed and working correctly. For more detailed information on
ImageMagick, refer to the ImageMagick web site.
Parent topic: Transformation API [50]
transformImage(mimetype)
Parameters
mimetype
The mimetype the document will be transformed to.
Returns
Returns the transformed image node if successful, or null if the transformation failed.
Example
// transform JPEG image file to BMP
var node = [Link]("WIND_TURBINE.JPG");
transformImage(mimetype, options)
transformImage(mimetype, options) this method transforms a document to a new document MIME type format. It copies the document, changes
the extension to match the new MIME type, and then applies the transformation. The transformed image node is returned if successful, or null
is returned if the transformation failed.
Parameters
mimetype
The mimetype the document will be transformed to.
options
Image convert command options.
Returns
Returns the transformed image node if successful, or null if the transformation failed.
transformImage(mimetype, destination)
this method transforms a document to a new document MIME type format. It copies the document,
transformImage(mimetype, destination)
changes the extension to match the new MIME type, and then applies the transformation.
Parameters
mimetype
The mimetype the document will be transformed to.
destination
The destination folder the transformed document will be output to.
Returns
Returns the transformed image node if successful, or null if the transformation failed.
Example
// transform image from JPEG to GIF and locate in destination folder
var node = [Link]("WIND_TURBINE.JPG");
var destDir = [Link]("TRANSFORMED_IMAGES");
transformImage(mimetype, options, destination) this method transforms an image to a new image format, applying the supplied ImageMagick
options. It copies the image document in the specified destination folder, changes the extension to match the new MIME type, and then applies
the transformation.
Parameters
mimetype
The mimetype the document will be transformed to.
options
Image convert command options.
destination
The destination folder the transformed document will be output to.
Returns
Returns the transformed image node if successful, or null if the transformation failed.
processTemplate
The processTemplate methods use the FreeMarker template processing services in Alfresco.
Parent topic: Transformation API [50]
processTemplate(template)
processTemplate(template) this method executes a FreeMarker template file against the node. The node is used as the context for the document
or space object in the templating default model.
Parameters
template
The node of the template to execute as a ScriptNode object.
Returns
Returns the transformed image node if successful, or null if the transformation failed.
processTemplate(template, args)
processTemplate(template, args) this method executes a FreeMarker template file against the node, passing the supplied array of name/value
pair arguments to the template. The node is used as the context for the document or space object in the templating default model.
Parameters
template
The node of the template to execute as a ScriptNode object.
args
An associative array containing the namevalue pairs of arguments to be passed to the template.
Returns
processTemplate(template)
processTemplate(template) this method executes a FreeMarker template file against the node. The node is used as the context for the document
or space object in the templating default model.
Parameters
template
The template to process passed as a string.
Returns
Returns the transformed image node if successful, or null if the transformation failed.
processTemplate(template, args)
processTemplate(template, args) this method executes a FreeMarker template file against the node, passing the supplied array of name/value
pair arguments to the template. The node is used as the context for the document or space object in the templating default model.
Parameters
template
The template to process passed as a string.
args
An associative array containing the namevalue pairs of arguments to be passed to the template.
Returns
Thumbnail API
A thumbnail is a transformation of content into a specified destination MIME type. This is most commonly an image of a particular size, but can
also be other things, for example, a Flash rendition. The ScriptNode class provides several methods for generating and handling thumbnails.
createThumbnail [94] The createThumbnail methods create a thumbnail based on the definition registered for the thumbnail name
provided.
getThumbnail [95]getThumbnail(thumbnailName) gets the given thumbnail for the content property.
getThumbnails [96]getThumbnails() gets all the thumbnails for a given node's content property.
getThumbnailDefinitions [97]getThumbnailDefinitions() returns the names of the thumbnail definitions that can be applied to the content
property of this node.
ScriptThumbnail Object [98] Certain thumbnail methods return ScriptThumbnail objects. These objects are an extension of the ScriptNode
object. ScriptThumbnail objects have a single method, update.
createThumbnail
The createThumbnail methods create a thumbnail based on the definition registered for the thumbnail name provided.
If the thumbnail name has not been registered, there will be an error.
createThumbnail(thumbnailName)
createThumbnail(thumbnailName,async) this method creates a thumbnail based on the definition registered for the thumbnail name provided.
If the thumbnail name has not been registered, there will be an error.
Parameters
thumbnailName
The thumbnail name. The thumbnail name corresponds to preset thumbnail details stored in the repository.
Returns
createThumbnail(thumbnailName,async)
createThumbnail(thumbnailName,async) this method creates a thumbnail based on the definition registered for the thumbnail name provided.
If the thumbnail name has not been registered, there will be an error.
Parameters
thumbnailName
The thumbnail name. The thumbnail name corresponds to preset thumbnail details stored in the repository.
async
Optional parameter
False by default, true if the thumbnail is to be created asynchronously. When set to false, the method blocks until the thumbnail is created
and the newly created thumbnail is returned. If set to true, the method queues the creation of the thumbnail asynchronously and
immediately returns to the calling client with null.
Returns
Returns the ScriptThumbnail object representing the newly created thumbnail.
getThumbnail
getThumbnail(thumbnailName) gets the given thumbnail for the content property.
Parameters
thumbnailName
The thumbnail name. The thumbnail name corresponds to preset thumbnail details stored in the repository.
Returns
Returns a ScriptThumbnail object representing the specified thumbnail.
Parent topic: Thumbnail API [51]
getThumbnails
getThumbnails() gets all the thumbnails for a given node's content property.
Returns
Returns a list of ScriptThumbnail objects. This is empty if none are available.
getThumbnailDefinitions
getThumbnailDefinitions() returns the names of the thumbnail definitions that can be applied to the content property of this node.
Thumbnail definitions only appear in this list if they can produce a thumbnail for the content found in the content property. This is determined by
looking at the MIME type of the content and the destination MIME type of the thumbnail.
Returns
Returns an array of thumbnail names that are valid for the current content type.
ScriptThumbnail Object
Certain thumbnail methods return ScriptThumbnail objects. These objects are an extension of the ScriptNode object. ScriptThumbnail objects
have a single method, update.
update
update() updates all the thumbnails for a particular node.
This method belongs to the ScriptThumbnail object, which extends the standard ScriptNode and represents a thumbnail object.
Properties
tags
An array of tag name strings. If a string array of tags is applied to this property they will overwrite the tags currently applied to the node.
isTagScope
A boolean. If true, the node is a tag scope node and false otherwise.
clearTags
clearTags()deletes all the tags from the node.
Parent topic: Tagging API [52]
addTag
addTag(tag) adds a single tag to a node.
Parameters
tag
The tag (as a string) to add to the node.
Returns
void
addTags
addTags(tags) adds several tags to a node.
Parameters
tags
A string array containing the tags to add to the node.
Returns
void
removeTag
removeTag(tag) removes the specified tag from a node.
Parameters
tag
The tag (as a string) to remove from the node.
removeTags
removeTags(tags) removes the specified tags from a node.
Parameters
tags
A string array containing the tags to remove from the node.
getTagScope
getTagScope() gets the nearest tag scope to this node by traversing up the parent hierarchy until one is found. If none is found, null is returned.
Returns
A TagScope object which represents the nearest tag scope, or null if one is not found.
setIsTagScope
setIsTagScope(boolean value) sets whether this node is a tag scope or not.
Parameters
value
True if this node is a tag scope, false otherwise.
Returns
void
childrenByTags
childrenByTags(tag) gets all children of the node that have the tag specified. The methods fetch the children of the node in a deep (recursive)
fashion.
Parameters
tag
A string representing the tag name.
Returns
An array of ScriptNode objects that corresponds to the children of the node with the specified tag.
Actions API
The actions API provides a root level actions object that allows invocation of Alfresco actions registered with the repository.
Properties
The following Action object properties are available to use within scripts:
Action Object Property Read/write Description
registered Readonly An array of strings representing the actions available.
create [108]create(name) returns the ScriptAction object with the name specified.
create
create(name) returns the ScriptAction object with the name specified.
Parameters
name
A string representing the name of the action to return a ScriptAction object for.
Returns
The ScriptAction object for the given action name, or null if the action name is not registered.
Classification API
The Classification API has two parts: manipulating classifications, and manipulating the categories they contain.
A root level classification object is provided to return category nodes. The CategoryNode objects returned from the methods are extended from
the standard JavaScript ScriptNode model to include category manipulation.
createRootCategory
createRootCategory(aspect, name) creates a root category.
Parameters
aspect
The classification aspect.
name
Name of root category to create.
Returns
A category node
Example
Parent topic: Classification API [12]
getAllCategoryNodes
getAllCategoryNodes(aspect) gets an array of all the category nodes in the given classification.
Parameters
aspect
The classification aspect.
Returns
Returns an array of CategoryNode objects in the given classification.
getAllClassificationAspects
getAllClassificationAspects() gets all the aspects that define a classification. An array of aspect QNames in prefix:localName form is returned.
Returns
Returns an array of strings representing aspects as QNames.
Example
[Link] = [Link]();
The previous code would return aspects such as cm:taggable, cm:generalclassifiable, cm:classifiable.
getCategory
getCategory(catRef) returns a category node.
Parameters
catRef
The category node reference.
Returns
A category node.
Example
.
getCategoryUsage
getCategoryUsage(aspect, maxCount) returns categories with the most number of objects. The number of categories returned is specified in
maxCount.
Parameters
aspect
The classification aspect / category.
maxCount
The maximum number of categories to return.
Returns
Scriptable object containing the top categories.
Example
.
getRootCategories
getRootCategories(aspect) returns an array of root category nodes for a given classification.
Parameters
aspect
The classification aspect.
Returns
Array of root category nodes.
Example
[Link] = [Link]("cm:generalclassifiable");
The previous code snippet would return category node names such as:
Languages
Regions
Tags
setStoreUrl
setStoreUrl(storeRef) sets the default store reference.
Parameters
String storeRef
The default store reference.
Returns
void
CategoryNode API
The CategoryNode objects returned from the classification object methods are extended from the standard JavaScript ScriptNode model.
Properties
isCategory
Returns true if this is a category node, or false otherwise. This is supported by all nodes types.
categoryMembers
Gets an array of all the members of this category at any depth
subCategories
Gets an array of all the subcategories of this category at any depth
membersAndSubCategories
Gets an array of all the subcategories and members of this category at any depth
immediateCategoryMembers
Gets an array of all the immediate members of this category (only direct members of this category and not through sub categories).
immediateSubCategories
Gets an array of all the immediate subcategories of this category (only direct subcategories of this category and not through
subcategories)
immediateMembersAndSubCategories
Gets an array of all the immediate subcategories and members of this category (only direct subcategories and members of this category
and not through subcategories)
createSubCategory [117]createSubCategory(name) creates a new subcategory from the current category node.
removeCategory [118]removeCategory() deletes the current category node.
rename [119]rename(name) renames the current category node to the specified name.
createSubCategory
createSubCategory(name) creates a new subcategory from the current category node.
Parameters
name
Name of the category to create.
Returns
Returns a CategoryNode representing the new subcategory created.
removeCategory
removeCategory()deletes the current category node.
Parent topic: CategoryNode API [116]
rename
rename(name) renames the current category node to the specified name.
Parameters
name
String representing the new name of the category node.
Logging API
A root level logger object provides a number of methods to help debug scripts.
Properties
loggingEnabled
True if logging is enabled.
debugLoggingEnabled
True if debug logging is enabled.
infoLoggingEnabled
True if info logging is enabled.
warnLoggingEnabled
True if warn logging is enabled.
errorLoggingEnabled
True if error logging is enabled.
[Link]("Debug string")
log
log(string) writes a message string to the log.
Parameters
string
A message string to write to the log.
warn
warn(string) writes a message string to the log.
Parameters
string
A message string to write to the log.
info
info(string) writes a message string to the log.
Parameters
string
A message string to write to the log.
error
error(string) writes a message string to the console.
Parameters
string
A message string to write to the log.
debug
debug(string) writes a debug message string to the log.
Parameters
string
A message string to write to the log.
People API
The People API provides access to Alfresco people and groups.
addAuthority [125]addAuthority(parentGroup, authority) adds an authority (User or Group ) to the specified parent group.
changePassword [126]changePassword(oldpassword, newpassword) changes the password for the current user only when the old password is
supplied.
createGroup [127] The createGroup methods are used to create groups.
createPerson [128]createPerson creates a person (cm:person) object.
deleteGroup [129]deleteGroup(group) removes a group from the system.
deletePerson [130] The deletePerson(username) method deletes a person with the given user name from the system.
disableAccount [131]disableAccount(userName) disables an enabled account. It can be invoked with Administrator authority only.
enableAccount [132]enableAccount(userName) enables a disabled account. It can be invoked with Administrator authority only.
getCapabilities [133]getCapabilities(person) returns a hash of the specified user's capabilities.
getContainerGroups [134]getContainerGroups(person) gets the groups that contain the specified authority.
getExcludeTenantFilter [135]getExcludeTenantFilter(person) returns a Boolean.
getGroup [136]getGroup(groupId) gets a group given the group ID.
getImmutableProperties [137]getImmutableProperties(username) returns a map of the person properties that are marked as immutable for
the given user.
getMembers [138]getMembers returns an array of people nodes belonging to the specified group (including all subgroups).
getPeople [139] The getPeople(...) methods get the collection of people stored in the repository.
getPeoplePaging [140]getPeoplePaging() gets the collection of people stored in the repository.
getPeopleEvaluationMode [141]ScriptNode getPeopleEvaluationMode(username) returns the permission evaluation mode.
getPerson [142]ScriptNode getPerson(username) returns a single (cm:person) node associated with the specified user name, or null if the
person does not exist.
getPersonFullName [143]ScriptNode getPersonFullName(username) avoids complete getProperties() retrieval for a cm:person when the script
only requires the full name of person.
isAccountEnabled [144]isAccountEnabled(userName) determines if the specified user's account is enabled.
isAdmin [145]isAdmin(person) determines if the specified user has Administrator authority.
isGuest [146]isGuest(person) determines if the specified user has Guest authority.
removeAuthority [147]removeAuthority(parentGroup, authority) removes an authority from a group.
setPassword [148]setPassword(userName, password) sets the password for the given user. It is executable with Administrator authority only.
setQuota [149]setQuota(person, quota) sets the quota content in bytes for the specified person. It can be invoked only by an Administrator
authority.
setStoreUrl [115]setStoreUrl(storeRef) sets the default store reference.
addAuthority
addAuthority(parentGroup, authority) adds an authority (User or Group ) to the specified parent group.
Parameters
parentGroup
The node representing the group to add the user or group to.
authority
A node representing the user or group to add.
Example
The following example will add [Link] to the administrators group.
if(group){
user = [Link]("[Link]");
try{
[Link](group, user);
}
catch (ex){
[Link] = "ABORT: Exception occurred: "+ex;
return;
}
}
If a probem occurs, for example the user cannot be found, an exception message will be generated such as the following:
ABORT: Exception occurred: JavaException: [Link]: Authority is a mandatory parameter
changePassword
changePassword(oldpassword, newpassword) changes the password for the current user only when the old password is supplied.
Parameters
oldpassword
A string representing the currently logged in user's current password.
newpassword
A string representing the currently logged in user's new password.
Example
[Link]("oldpwd", "newpwd");
createGroup
The createGroup methods are used to create groups.
Parent topic: People API [14]
createGroup(groupName)
createGroup(groupName) this method creates a new toplevel where groupName is the unique group name to create.
Parameters
group
The unique group name to create
Example
var groupName = "TECH_WRITERS";
var newGroup = [Link]("GROUP_"+groupName);
if(!newGroup){
newGroup = [Link](groupName);
}
createGroup(parentGroup,groupName)
createGroup(parentGroup, groupName) this method creates a new group as a child of the specified parent group node. This can be null for a top
level group.
Parameters
parentGroup
The parent group
groupName
The group name
Example
var parentGroupName = "TECH_WRITERS";
var parentGroup = [Link]("GROUP_"+parentGroupName);
var subGroup = "TECH_WRITER_ELITE"; // do not prefix with GROUP_
if(parentGroup){
newGroup = [Link](parentGroup, subGroup);
[Link] = newGroup;
}
createPerson
createPersoncreates a person (cm:person) object.
Parent topic: People API [14]
createPerson(username)
Parameters
userName
A string representing the user name for the user to be created.
Returns
Returns the person node created or null if the user name already exists.
createPerson(userName, firstName, lastName, emailAddress) creates a person (cm:person) with a generated user name.
Parameters
userName
A string representing the username for the user to be created.
firstName
A string representing the user's first name.
lastName
A string representing the user's last name.
emailAddress
A string representing the user's email address.
Returns
Returns the person node created or null if the user cannot be created.
createPerson(username, firstName, lastName, emailAddress, password, setAccountEnabled) creates a person (cm:person) with a generated user
name.
Parameters
userName
A string representing the username for the user to be created.
firstName
A string representing the user's first name.
lastName
A string representing the user's last name.
emailAddress
A string representing the user's email address.
setAccountEnabled
A boolean. Set to true to create an enabled user account. Set to false to create a disabled user account.
Returns
Returns the person node created or null if the user cannot be created.
createPerson(username, firstName, lastName, emailAddress, password, setAccountEnabled, notifyByEmail) creates a person (cm:person) with a
generated user name.
Parameters
userName
A string representing the username for the user to be created.
firstName
A string representing the user's first name.
lastName
A string representing the user's last name.
emailAddress
A string representing the user's email address.
setAccountEnabled
A boolean. Set to true to create an enabled user account. Set to false to create a disabled user account.
notifyByEmail
A boolean. Set to true to have an automated email sent to the user's account when the account is created. This only works if the
username and password are provided. If set to false no email will be sent.
Returns
Returns the person node created or null if the user cannot be created.
Example
var testUser = [Link]("[Link]", "Joe", "User", "[Link]@[Link]", "password", true, true);
if (testUser){
// user account created
}
deleteGroup
deleteGroup(group) removes a group from the system.
Parameters
group
The group to delete.
Example
var node = [Link]("GROUP_TECH_WRITERS");
if(node){
[Link](node);
}
deletePerson
The deletePerson(username) method deletes a person with the given user name from the system.
Parameters
username
The user name of the person to delete.
Example
[Link]("[Link]");
disableAccount
disables an enabled account. It can be invoked with Administrator authority only.
disableAccount(userName)
Note: This procedure works for alfrescoNtlm users only.
Parameters
userName
A string representing the user name of the user whose account is to be disabled.
Example
The following code snippet toggles the user account status:
if([Link]("Joe")){
[Link]("Joe");
}
else{
[Link]("Joe");
}
enableAccount
enableAccount(userName) enables a disabled account. It can be invoked with Administrator authority only.
Parameters
userName
A string representing the user name of the user whose account is to be enabled.
Example
The following code snippet toggles the user account status:
if([Link]("Joe")){
[Link]("Joe");
}
else{
[Link]("Joe");
}
getCapabilities
getCapabilities(person) returns a hash of the specified user's capabilities.
Parameters
person
A node representing the user whose capabilities are to be fetched.
Returns
A <string, boolean> hash containing the capabilities of the user. For example, isMutable, isGuest, isAdmin and their boolean states will be
returned.
Example
The following code snippet returns a hash containing the capabilities of the admin user:
var person = [Link]("admin");
if (person){
[Link] = [Link](person);
}
isMutable: TRUE
isGuest: FALSE
isAdmin: TRUE
getContainerGroups
getContainerGroups(person) gets the groups that contain the specified authority.
Parameters
person
The user (cm:person) to get the containing groups for.
Example
The following code returns a list of groups that abeecher is a member of:
var user = [Link]("abeecher");
if(user){
[Link] = [Link](user);
}
Parent topic: People API [14]
getExcludeTenantFilter
getExcludeTenantFilter(person) returns a Boolean.
Parameters
None
Returns
A boolean.
getGroup
getGroup(groupId) gets a group given the group ID.
Parameters
groupId
A string representing the groupId of the group to return.
Returns
Returns a ScriptGroup object, or null if the group cannot be found.
Example
function main()
{
//
// Get the person details
//
// return error message if a person with that user name could not be created
if (person === null)
{
[Link](status.STATUS_CONFLICT, "User name already exists: " + userName);
return;
}
// set quota if any ‐ note that only Admin can set this and will be ignored otherwise
var quota = ([Link]("quota") ? [Link]("quota") : ‐1);
[Link](person, [Link]());
// apply groups if supplied ‐ note that only Admin can successfully do this
if ([Link]("groups"))
{
var groups = [Link]("groups");
for (var index=0; index<[Link](); index++)
{
var groupId = [Link](index);
var group = [Link](groupId);
if (group != null)
{
[Link](group, person);
}
}
}
main();
getImmutableProperties
getImmutableProperties(username) returns a map of the person properties that are marked as immutable for the given user.
This enables a script to interrogate which properties are dealt with by an external system such as LDAP and should not be mutable in any
client UI.
Parameters
username
A string representing the username of the user whose immutable properties are to be fetched.
Returns
A ScriptableHashMap containing the immutable properties of the specified user.
Example
var person = [Link]("abeecher");
if (person){
[Link] = [Link](person);
}
getMembers
getMembersreturns an array of people nodes belonging to the specified group (including all subgroups).
Parent topic: People API [14]
getMembers
Parameters
group
A node representing the group whose members will be fetched.
Returns
Returns an array of people nodes belonging to the specified group (including all subgroups).
Example
The following code would fetch all members of the administrators group and any subgroups.
if(node){
[Link] = [Link](node);
}
getMembers
getMembers(group, recurse) gets specified group members. Will not recurse into subgroups if recurse is set to false.
Parameters
group
A node representing the group whose members will be fetched.
recurse
Set to true to recurse into subgroups. Set to false to turn off recursion.
Returns
Returns an array of people nodes belonging to the specified group or people of subgroups if recurse was set to true.
Example
The following code would fetch all members of the administrators group, but not the members of any subgroups.
var node = [Link]("GROUP_ALFRESCO_ADMINISTRATORS");
if(node){
[Link] = [Link](node, false);
}
getPeople
The getPeople(...) methods get the collection of people stored in the repository.
Parent topic: People API [14]
getPeople(filter)
An optional filter query can be provided by which to filter the people collection. Space separates the query terms, for example "john bob" will
find all users whose first or second names contain the strings "john" or "bob".
CAUTION:
This method is deprecated in version 4.0 and above.
Parameters
filter
This is a query string by which to filter the collection of people. If null then all people stored in the repository are returned.
Returns
Example
var user;
var nodes = [Link](null);
for each(var node in nodes)
{
[Link](node);
user = [Link](node);
[Link]([Link]["cm:userName"] + " '"
+ [Link]["cm:firstName"] + "' '"
+ [Link]["cm:lastName"] + "'");
}
getPeople(filter, maxResults)
An optional filter query can be provided by which to filter the people collection. Space separates the query terms, for example "john bob" will
find all users whose first or second names contain the strings "john" or "bob".
Parameters
filter
This is a query string by which to filter the collection of people. If null then all people stored in the repository are returned.
maxResults
The maximum number of results to return. Returns all results if this value is set to be less than or equal to zero.
Returns
Example
The following snippet would return all users whose first or last names contained the string "fred". The results are limited to a maximum of 10
results:
getPeople(filter, maxResults, sortBy, sortAsc) get the collection of people stored in the repository.
An optional filter query can be provided by which to filter the people collection. Space separates the query terms, for example "john bob" will
find all users whose first or second names contain the strings "john" or "bob". This method supports sorting by specifying sortBy and sortAsc
parameters.
Parameters
filter
This is a query string by which to filter the collection of people. If null then all people stored in the repository are returned.
maxResults
The maximum number of results to return. Returns all results if this value is set to be less than or equal to zero.
sortBy
The field for sorting.
sortAsc
Set to true to sort results in ascending order.
Returns
Example
The following snippet would return all users whose first or last names contained the string "fred", sorted in ascending order on lastName. The
results are limited to a maximum of 10 results:
[Link] = [Link]("fred", 10, "lastName", true);
getPeoplePaging
getPeoplePaging() gets the collection of people stored in the repository.
Parameters
filter
This is a query string by which to filter the collection of people. If null then all people stored in the repository are returned.
pagingRequest
A ScriptPagingDetails object.
sortBy
The field for sorting.
sortAsc
Set to true to sort results in ascending order.
Returns
Returns a collection of people objects as a JavaScript array, with Paging.
Example
Parent topic: People API [14]
getPeopleEvaluationMode
ScriptNode getPeopleEvaluationMode(username) returns the permission evaluation mode.
Parameters
None
Returns
Permission evaluation mode.
getPerson
ScriptNode getPerson(username) returns a single (cm:person) node associated with the specified user name, or null if the person does not exist.
Parameters
username
A string representing the user name for the user who is being fetched.
Returns
A node representing the user requested, or null if the user name cannot be found.
Example
The following code snippet returns the node object for the user with the username abeecher:
[Link] = [Link]("abeecher");
getPersonFullName
ScriptNode getPersonFullName(username) avoids complete getProperties() retrieval for a cm:person when the script only requires the full name of
person.
Parameters
username
A string representing the user name of the user for which to return the full name.
Returns
Full name of the person or null if the user does not exist in the system.
Example
The following code snippet returns the full name for the user with the username abeecher:
[Link] = [Link]("abeecher");
isAccountEnabled
isAccountEnabled(userName) determines if the specified user's account is enabled.
Parameters
userName
A string representing the user name of the user whose account is to be checked.
Returns
Returns true if the specified user account is enabled, false if the account is currently disabled.
Example
The following code snippet toggles the user account status:
if([Link]("Joe")){
[Link]("Joe");
}
else{
[Link]("Joe");
}
isAdmin
isAdmin(person) determines if the specified user has Administrator authority.
Parameters
person
A node representing the user to check.
Returns
Returns true if the specified user is an Administrator authority.
Example
var userName = "abeecher";
if(user){
[Link] = [Link](user);
[Link] = userName;
}
isGuest
isGuest(person) determines if the specified user has Guest authority.
Parameters
person
A node representing the user to check.
Returns
Returns true if the specified user is logged in as a guest.
Example
var userName = "abeecher";
if(user){
[Link] = [Link](user);
[Link] = userName;
}
removeAuthority
removeAuthority(parentGroup, authority) removes an authority from a group.
Parameters
parentGroup
The node representing the group to remove the user or group from.
authority
A node representing the user or group to remove.
Example
The following code will remove the user abeecher from the test group.
var group = [Link]("GROUP_TEST");
if(group){
user = [Link]("abeecher");
try{
[Link](group, user);
}
catch (ex){
[Link] = "ABORT: Exception occurred: "+ex;
return;
}
}
If a probem occurs, for example the user cannot be found, an exception message will be generated such as the following:
ABORT: Exception occurred: JavaException: [Link]: Authority is a mandatory parameter
setPassword
setPassword(userName, password) sets the password for the given user. It is executable with Administrator authority only.
Parameters
userName
A string representing the user name of the user to set the password for.
password
A string representing the password to assign for the user specified.
Example
[Link]("[Link]", "newpwd");
setQuota
setQuota(person, quota) sets the quota content in bytes for the specified person. It can be invoked only by an Administrator authority.
Parameters
person
A node representing the user to set the quota for.
quota
A string representing the quota in bytes to allocate to the specified user. A value of 1 means no quota is set.
Example
The following code sets the quota to 10 MB for the user abeecher:
var userName = "abeecher";
var user = [Link](userName);
if (user){
[Link](user, "10240000"); // 10 MB
}
setStoreUrl
setStoreUrl(storeRef) sets the default store reference.
Parameters
String storeRef
The default store reference.
Returns
void
ScriptAction API
A ScriptAction represents an Alfresco action registered within the repository.
Properties
name
Returns the name of the action
parameters
An associative array (map) of the parameters for the action
execute [150] The execute() methods execute the action against the specified node.
executeAsynchronously [151]executeAsynchronously(node) executes the action against the specified node asynchronously.
execute
The execute() methods execute the action against the specified node.
Parent topic: ScriptAction API [15]
execute(node)
The action (and its parameters) can be reused against many nodes by repeatedly invoking execute. Between invocations, the parameters of
the action can be changed.
Parameters
node
The node on which to execute the action.
Example
Executing the mail action:
execute(node, readOnly, newTxn) executes the action against the specified node.
The action (and its parameters) can be reused against many nodes by repeatedly invoking execute. Between invocations, the parameters of
the action can be changed.
Parameters
node
The node on which to execute the action.
readOnly
Set to true to start a readonly transaction, false otherwise.
newTxn
Set to true to start a new transaction, false to use the existing transaction.
execute(nodeRef)
The action (and its parameters) can be reused against many nodes by repeatedly invoking execute. Between invocations, the parameters of
the action can be changed.
Parameters
nodeRef
The node on which to execute the action.
execute(nodeRef, readOnly, newTxn) executes the action against the specified node.
The action (and its parameters) can be reused against many nodes by repeatedly invoking execute. Between invocations, the parameters of
the action can be changed.
Parameters
nodeRef
The node on which to execute the action.
readOnly
Set to true to start a readonly transaction, false otherwise.
newTxn
Set to true to start a new transaction, false to use the existing transaction.
executeAsynchronously
executeAsynchronously(node) executes the action against the specified node asynchronously.
The action (and its parameters) can be reused against many nodes by repeatedly invoking execute. Between invocations, the parameters of
the action can be changed.
When called, this method returns immediately, with the action executing in a separate thread.
Parameters
node
The node on which to execute the action.
Local searches can be performed using the ScriptNode APIs childByNamePath and childByXPath. Like the various node objects, the search object
is part of the root scope.
findNode [152]findNode methods allow you to search for a single node by node reference object, or node reference string. By default the
method assumes you are searching for a node that is a descendent of CompanyHome.
ISO9075Decode [153]ISO9075Decode(string value) is a helper to decode a ISO9075encoded string for Lucene PATH statements.
ISO9075Encode [154]ISO9075Encode(string value) is a helper to encode a value into ISO9075encoded format for Lucene PATH
statements.
isValidXpathQuery [155]isValidXpathQuery(query) checks the validity of an XPath query string.
luceneSearch [156] The luceneSearch methods provide search operations using the Lucene search syntax.
query [157]query(search) performs a search on ScriptNode objects.
savedSearch [158]savedSearch(node) returns an array of ScriptNode objects that were found by executing the Saved Search referenced by
the supplied node object. The node object contains the XML that represents the saved search.
selectNodes [159] The selectNodes methods perform an XPath search and return a list of found nodes.
tagSearch [160]tagSearch(store, tag) performs a search on a given tag in a given store.
xpathSearch [161]xpathSearch(xpath) performs an XPath search.
findNode
findNodemethods allow you to search for a single node by node reference object, or node reference string. By default the method assumes you
are searching for a node that is a descendent of CompanyHome.
Parent topic: Search API [16]
findNode(noderef)
findNode(noderef)
This method returns a single ScriptNode as specified by the NodeRef object for that node.
Parameters
noderef
Node reference of the node to find.
Returns
Example
var foundNode = [Link](nodeRef);
findNode(noderef)
findNode(noderef)
This method returns a single ScriptNode as specified by the string form of the NodeRef for that node, null is returned if the search failed.
Parameters
noderef
A node reference as a string.
Returns
Example
foundNode = [Link](nodeRefString);
...
}
findNode(referenceType, reference)
findNode(referenceType, reference)
Parameters
referenceType
The reference type. The reference type can be one of:
node
path
reference
The reference elements supplied depend on the reference type:
Returns
Example
var referenceType = "node";
// Store type, store id, node id
var reference = ["workspace", "SpacesStore", "78eb920f‐fd46‐41ee‐9fdb‐099e96da8349"];
var foundNode = [Link](referenceType, reference);
ISO9075Decode
ISO9075Decode(string value) is a helper to decode a ISO9075encoded string for Lucene PATH statements.
Parameters
string
The string to decode.
Returns
Returns a decoded string.
Example
The following code:
ISO9075Encode
ISO9075Encode(string value) is a helper to encode a value into ISO9075encoded format for Lucene PATH statements.
Parameters
string
The string to encode. Characters within the string that need to be encoded to ISO9075 will take the format _xDDDD_, where DDDD is the
hex value of the character.
Returns
Returns a ISO9075 encoded string.
Example
The following code:
var rawString = "//test:123 DIR/[Link] @";
var encodedString = search.ISO9075Encode(rawString);
var decodedString = search.ISO9075Decode(encodedString);
rawString: @cm:name:"banana"
encodedString: _x0040_cm_x003a_name_x003a__x0022_banana_x0022_
decodedString: @cm:name:"banana"
isValidXpathQuery
isValidXpathQuery(query) checks the validity of an XPath query string.
Parameters
query
Returns
Returns true is the query is a valid XPath query string, false otherwise.
Example
The method can be used to check the validity of a XPath query prior to use:
if ([Link](query)){
nodes = [Link](query);
}
else {
// ...
}
luceneSearch
The luceneSearch methods provide search operations using the Lucene search syntax.
Parent topic: Search API [16]
luceneSearch(search)
Parameters
search
The search terms and operators that represent the Lucene search phrase.
Returns
Returns an array of ScriptNode objects that were found by the Alfresco repository Lucene search.
Example
luceneSearch(store, search)
Parameters
store
The given store, for example workspace://SpacesStore.
search
The search terms and operators that represent the Lucene search phrase.
Returns
Returns an array of ScriptNode objects that were found by the Alfresco repository Lucene search in the given store.
Example
luceneSearch(search, sortColumn, asc) this method performs a Lucene search by property and a specified sort order.
Parameters
search
The search terms and operators that represent the Lucene search phrase.
sortColumn
The property name to sort on.
asc
The sort order. If set to true the results are ordered in ascending order based on the property specified. If false the results are sorted in
descending order.
Returns
Returns an array of ScriptNode objects satisfying the search criteria sorted by the specified sortColumn and asc.
Example
var nodes = [Link]("TEXT:alfresco", "@cm:modified", false);
This method performs a Lucene search by property and a specified sort order in the given store.
Parameters
store
The given store
search
The search terms and operators that represent the Lucene search phrase.
sortColumn
The property name to sort on
asc
The sort order. If set to true the results are ordered in ascending order based on the property specified. If false the results are sorted in
descending order.
Returns
Returns an array of ScriptNode objects satisfying the search criteria and sorted by the specified sortColumn and asc in the given store.
Example
var nodes = [Link]("workspace://SpacesStore", "TEXT:alfresco", "@cm:modified", true);
luceneSearch(search, sortColumn, asc, max) this method performs a Lucene search by property and a specified sort order in the specified store.
The number of results returned can be limited.
Parameters
search
The search terms and operators that represent the Lucene search phrase.
sortColumn
The property name to sort on
asc
The sort order. If set to true the results are ordered in ascending order based on the property specified. If false the results are sorted in
descending order.
max
The maximun number of items to return in the search results.
Returns
Returns an array of ScriptNode objects satisfying the search criteria and sorted by the specified sortColumn and asc. The results are limited to the
number specified by the max parameter.
Example
var nodes = [Link]("TEXT:alfresco", "@cm:modified", true, 50);
luceneSearch(store, search, sortColumn, asc, max) this method performs a Lucene search by property and a specified sort order in the give
store.
Parameters
store
The given store
search
The search terms and operators that represent the Lucene search phrase.
sortColumn
The property name to sort on
asc
The sort order. If set to true the results are ordered in ascending order based on the property specified. If false the results are sorted in
descending order.
max
The maximun number of items to return in the search results.
Returns
Returns an array of ScriptNode objects satisfying the search criteria and sorted by the specified sortColumn and asc in the given store. Results
are limited to the number specified by the parameter max.
Example
var nodes = [Link]("workspace://SpacesStore", "TEXT:alfresco", "@cm:modified", true, 50);
query
query(search) performs a search on ScriptNode objects.
Parameters
search
sort
{
column: string, mandatory, sort column in appropriate format for the language
ascending: boolean optional, defaults to false
}
page
{
maxItems: int, optional, max number of items to return in result set
skipCount: int optional, number of items to skip over before returning results
}
template
{
field: string, mandatory, custom field name for the template
template: string mandatory, query template replacement for the template
}
Returns
Returns an array of ScriptNode objects representing the search results.
Example
The search object defines the search to be executed as is constructed in this way:
var sort1 =
{
column: "@{[Link]
ascending: false
};
var sort2 =
{
column: "@{[Link]
ascending: false
};
var paging =
{
maxItems: 100,
skipCount: 0
};
var def =
{
query: "cm:name:test*",
store: "workspace://SpacesStore",
language: "fts‐alfresco",
sort: [sort1, sort2],
page: paging
};
This interface supports multicolumn sorting and any of the Alfresco search languages. Future versions of the API will allow the search
definition objects to be extended with additional properties while maintaining backward compatibility.
savedSearch
savedSearch(node)returns an array of ScriptNode objects that were found by executing the Saved Search referenced by the supplied node object.
The node object contains the XML that represents the saved search.
Parameters
node
The node object representing the saved search node.
Returns
Array of ScriptNode objects
Example
var node = [Link]("Data Dictionary/Saved Searches/SilverSearch");
if (node){
var nodes = [Link](node);
[Link] = nodes;
[Link] = "Nodes found from saved search:";
}
else{
[Link] = "Saved search not found";
}
savedSearch(noderef)
savedSearch(noderef) this method returns an array of ScriptNode objects that were found by executing the Saved Search referenced by the
supplied noderef string.
Parameters
noderef
The noderef string representing the saved search node.
Returns
Example
var node = [Link]("Data Dictionary/Saved Searches/GoldSearch");
if (node){
if ([Link](nodeRefString)){
var nodes = [Link](nodeRefString);
[Link] = nodes;
[Link] = "Nodes found from saved search:";
}
else{
[Link] = "nodeRefString not valid!";
}
}
else{
[Link] = "Saved search not found";
}
selectNodes
The selectNodes methods perform an XPath search and return a list of found nodes.
This method uses the underlying Node Service to perform a search. While this method provides full support for XPath syntax by using Jaxen,
use of the Node Service means that searches might be less performant, especially for queries such as unconstrained fulltext searches. For
searches of such a nature it might be better to use xpathSearch(), which provides indexbased searching at the cost of a more limited XPath
syntax.
CAUTION:
The following operators should be avoided or used with caution as they can potentially consume considerable resources:
selectNodes with //
selectNodes with /*
selectNodes with like
In general, avoid using selectNodes() unless you are looking for a specific path.
It is generally preferable to use a query language that searches against an index. This avoids potential excessive consumption of resources.
Comparison between searching with the Node Service and using indexbased searching, plus further information on supported syntax can be
found in the developer Wiki [162].
selectNodes(search)
selectNodes(search)
Parameters
search
Returns
selectNodes(store, search)
selectNodes(store, search)
Parameters
store
search
Returns
Returns an array of ScriptNode objects representing the search results.
Example
var searchString = "//*"; // XPath search string
var store = "workspace://SpacesStore";
Presentation Templates
Space Templates
RSS Templates
Node Templates
tagSearch
tagSearch(store, tag) performs a search on a given tag in a given store.
Parameters
store
The store in which to search. The default is workspace://SpacesStore if null is provided for this parameter.
tag
The tag to search for. Any node with this tag will be returned as part of an array of nodes.
Returns
Returns an array of ScriptNode objects that represent the nodes within the store that have the given tag applied.
Examples
var store = "workspace://SpacesStore";
var tag = "mining";
var nodes = [Link](store, tag);
xpathSearch
xpathSearch(xpath) performs an XPath search.
This method executes a search using a Lucenebased indexed query. The support for XPath is restricted but optimized. Being indexbased,
this method can offer better performance than Node Service based methods such as selectNodes(), for searches such as unconstrained full
text searches across large numbers of nodes.
Comparison between searching with the Node Service and using indexbased searching, plus further information on supported syntax can be
found in the developer Wiki [162].
Parameters
xpath
The XPath search string
Returns
Returns an array of ScriptNode objects that were found by the Alfresco repository XPath search.
Example
var query = "//";
var nodes = [Link](query);
xpathSearch(store, xpath)
xpathSearch(store, xpath)
Parameters
store
The given store
xpath
The XPath string
Returns
Returns an array of ScriptNode objects that were found by the Alfresco repository XPath search in the given store.
Example
var query = "//";
var store = "archive://SpacesStore";
var nodes = [Link](store, query);
Session API
A root level session object is provided to access the servelt web session.
Properties
id
Gets the session ID.
getValue [163]object getValue(string name) returns an attribute value from the session.
setValue [164]void setValue(string name, object value) add or set an attribute for the session.
removeValue [165]void removeValue(string name) remove an attribute from the session.
getValue
object getValue(string name) returns an attribute value from the session.
Parameters
String name
The name of the servelt web session attribute to return a value for.
Returns
An object representing the value of the attribute.
setValue
void setValue(string name, object value) add or set an attribute for the session.
Parameters
String name
The name of the servlet web session attribute to add or set a value for.
object value
The value of the attribute to set or add to the session object.
Returns
void
removeValue
void removeValue(string name) remove an attribute from the session.
Parameters
String name
The name of the servlet web session attribute to remove from the session object.
Returns
void
SessionTicket API
A root level sessionticket object is provided to access the current logged in user session ticket as a string value.
Properties
ticket
Gets the current authentication ticket.
Utility methods
A root level utils object is provided as a library of helper methods that are missing from generic JavaScript.
createPaging [166] The createPaging methods are used to build a ScriptPagingDetails object from the parameters supplied.
disableRules [167]disableRules disables rule execution for the current thread.
displayPath [168]displayPath(node) returns the cm:name display path for a node with minimum performance overhead.
enableRules [169]enableRules enables rule execution for the current thread.
fromISO8601 [170]fromISO8601(string) parses a date from an ISO8601 formatted string.
getLocale [171]getLocale returns the locale string for the current thread.
getNodeFromString [172]getNodeFromString(noderef) returns a ScriptNode object representing the supplied NodeRef string. The node is not
confirmed to exist in the repository.
longQName [173]longQName(string) returns the long version of a short prefixed QName.
moduleInstalled [174]moduleInstalled(moduleName) checks if a module is installed.
pad [175]pad(string, length) pads a string with leading zeros to the specified length.
setLocale [176]setLocale sets the locale for the current thread.
setServiceRegistry [177]setServiceRegistry(services) sets the service registry.
setNodeService [178]setNodeService(nodeService) sets the node service.
shortQName [179]shortQName(string) returns the short, or prefix, version of a long QName.
toBoolean [180]toBoolean(string) returns a Boolean object from a string value.
toISO8601(Date) [181]toISO8601(Date) formats a date to an ISO8601 formatted string.
toISO8601(long) [182]toISO8601(long) formats a time in milliseconds to an ISO8601 formatted string.
createPaging
The createPaging methods are used to build a ScriptPagingDetails object from the parameters supplied.
Parent topic: Utility methods [19]
createPaging(maxItems, skipCount)
Builds a ScriptPagingDetails object from the supplied parameters.
Parameters
maxItems
An integer value which sets the maximum number of results to return.
skipCount
The number of results to skip.
Returns
Parameters
maxItems
An integer value which sets the maximum number of results to return.
skipCount
The number of results to skip.
queryExecutionId
Reserved for future use.
Returns
createPaging(args)
Returns a ScriptPagingDetails object built from the supplied Args object. The Args object contains a map of parameters which must use their
standard names, such as maxItems, and skipCount.
Parameters
args
A map containing the parameters (using their standard names) and their corresponding values.
Returns
Returns a ScriptPagingDetails object.
disableRules
disableRulesdisables rule execution for the current thread.
Parent topic: Utility methods [19]
displayPath
displayPath(node) returns the cm:name display path for a node with minimum performance overhead.
Parameters
node
The script node.
Returns
Returns a cm:name based human readable display path for the give node.
enableRules
enableRules enables rule execution for the current thread.
Parent topic: Utility methods [19]
fromISO8601
fromISO8601(string) parses a date from an ISO8601 formatted string.
Parameters
isoDateString
An ISO8601 formatted string to convert to a datetime object.
Returns
A date object.
Example
var date = new Date();
var timeInMillisecs = [Link]();
var ISODate = utils.toISO8601(timeInMillisecs);
var origDate = utils.fromISO8601(ISODate);
The preceding code snippet would result in the ISO8601 formatted string 2011‐11‐28T17:06:51.477Z being converted to the datetime object Nov
28, 2011 5:06:51 PM.
getLocale
getLocale returns the locale string for the current thread.
Returns
Returns the locale string for the current thread.
Example
var localeString = [Link]();
The preceding code snippet would return a locale string such as en_US.
getNodeFromString
getNodeFromString(noderef) returns a ScriptNode object representing the supplied NodeRef string. The node is not confirmed to exist in the
repository.
Parameters
noderef
The noderef string
Returns
Returns a ScriptNode object corresponding to the node referenced by the supplied NodeRef string.
longQName
longQName(string) returns the long version of a short prefixed QName.
Parameters
string
Returns
Returns a string of the long version of a QName.
Example
var longQName = [Link]("cm:content");
moduleInstalled
moduleInstalled(moduleName) checks if a module is installed.
Parameters
moduleName
A string representing the module name, for example [Link].
Returns
True if the specified module is installed.
Example
var result = false;
result = [Link]("[Link]");
[Link] = result;
The preceding code snippet would return result as true if the module was installed.
pad
pad(string, length) pads a string with leading zeros to the specified length.
Parameters
string
The string to pad with leading '0' characters.
length
The length of the padded string.
Returns
Returns the new string.
setLocale
setLocale sets the locale for the current thread.
Parameters
localeString
A locale string in ISO format, ISOLanguageCode_ISOCountryCode, for example en_US.
Example
[Link]("en_US");
The preceding code snippet would set the locale for the current thread to en_US.
setServiceRegistry
setServiceRegistry(services) sets the service registry.
Parameters
services
The Service Registry.
Returns
void
setNodeService
setNodeService(nodeService) sets the node service.
Parameters
nodeService
The Node Service to set.
Returns
void
shortQName
shortQName(string) returns the short, or prefix, version of a long QName.
Parameters
string
Returns
Returns a string of the prefix version of a QName.
Example
var shortQName = [Link]("{[Link]
toBoolean
toBoolean(string) returns a Boolean object from a string value.
Parameters
booleanString
A boolean string, true or false.
Returns
Boolean value
Example
var booleanString = "true";
[Link] = [Link](booleanString);
The preceding code snippet would return a boolean value for result of true.
toISO8601(Date)
toISO8601(Date) formats a date to an ISO8601 formatted string.
Parameters
Date
Date object to convert.
Returns
The date converted to an ISO8601 formatted string.
Example
var date = new Date();
var ISODate = utils.toISO8601(date);
The preceding code snippet would result in the datetime Nov 28, 2011 4:50:16 PM being converted to 2011‐11‐28T16:43:57.039Z.
toISO8601(long)
toISO8601(long) formats a time in milliseconds to an ISO8601 formatted string.
Parameters
timeInMillis
A Long representing the time in millseconds to convert.
Returns
The time as an ISO8601 formatted string.
Example
var date = new Date();
var timeInMillisecs = [Link]();
var ISODate = utils.toISO8601(timeInMillisecs);
The preceding code snippet would convert the time in milliseconds 1,322,499,360,718 to the ISO8601 date time string 2011‐11‐28T16:56:00.718Z.
Services API
The Alfresco JavaScript Services API provides an interface to core Alfresco services that can be accessed from web scripts.
The JavaScript Services API provides an interface from web scripts to a number of core Alfresco services including:
Activities service
Authority service
Rendition service
Site service
Tagging service
Thumbnail service
Workflow service
Activities service [183] Activities refer to updates to content within a site, including uploaded files, blogs, discussions, calendars, and the
team wiki. The methods available for the Activities service are grouped into the Post activity and Feed controls object types.
Authority service [184] Authority is a general term to describe a group, user, or role. The authority service provides the following methods
to retrieve groups. The authority service makes the groups root object available.
Rendition service [185] A rendition is an alternative representation of a content node. Renditions are derived from their source nodes and
are usually updated automatically when their source node is updated.
Site service [186] A site is a collaborative area for a unit of work or a project. Sites are created in Share, and manipulated in various ways
directly using the UI or through web scripts or the REST API.
Tagging service [187] A tag is a nonhierarchical keyword or term assigned to a piece of information. The root object used to access these
services is taggingService.
Thumbnail service [188] A thumbnail is a transformation of content into a specified destination MIME type. This is most commonly an
image of a particular size, but can also be other things, for example, a Flash rendition. The Thumbnail service transforms and maintains
this thumbnail.
Workflow service [189] The Workflow JavaScript API lets you access Alfresco advanced workflows from within JavaScript.
Activities service
Activities refer to updates to content within a site, including uploaded files, blogs, discussions, calendars, and the team wiki. The methods
available for the Activities service are grouped into the Post activity and Feed controls object types.
getFeedControls [190]getFeedControls() gets feed control objects for the current user.
postActivity [191] The postActivity methods enable the posting of activities.
setFeedControl [192]setFeedControl(siteId, appToolId) sets the feed control for a site, an appTool, or a site/appTool combination for the
current user.
unsetFeedControl [193]unsetFeedControl(siteId,appTool) unsets the feed control for a site, an appTool, or a site/appTool combination for
the current user.
getFeedControls
getFeedControls() gets feed control objects for the current user.
Returns
Returns an array of FeedControl objects.
Example
The following code snippet would return a list of feed controls for the current user:
[Link] = [Link]();
The following FreeMarker code could then be used to enumerate these objects:
postActivity
The postActivity methods enable the posting of activities.
Parent topic: Activities service [183]
Parameters
activityType
Required. Activity type name specified in package format, for example [Link]‐created.
siteId
Required parameter to get site members and to apply feed controls.
appTool
Optional parameter. The application id or component id generating the activity, for example calendarComponent. If set, then feed controls
can be applied.
jsonActivityData
Required. The activity data, which can be accessed by the activity templates.
Returns
void
Example
[Link]("[Link]‐created", "mysite1", "calendarComponent", '{ "item1" : 123 }');
this method posts a predefined activity type and looks up activity data asynchronously
postActivity(activityType, siteId, appTool, nodeRef)
including name, displayPath, typeQName, firstName (of posting user), lastName (of posting user).
Parameters
activityType
Required. Activity type name specified in package format, for example [Link]‐created.
siteId
Required parameter to get site members and to apply feed controls.
appTool
Optional parameter. The application id or component id generating the activity, for example calendarComponent. If set, then feed controls
can be applied.
nodeRef
Required. This allows the activity service to look up some generic data for the node.
postActivity(activityType, siteId, appTool, nodeRef, beforeName) this method posts a predefined activity type, for example, for checked out
nodeRef or renamed nodeRef
Parameters
activityType
Required. Activity type name specified in package format, for example [Link]‐created.
siteId
Required parameter to get site members and to apply feed controls.
appTool
Optional parameter. The application id or component id generating the activity, for example calendarComponent. If set, then feed controls
can be applied.
nodeRef
Required. This allows the activity service to look up some generic data for the node.
beforeName
The name of the node prior to the name change.
postActivity(activityType,siteId,appTool,nodeRef,name,typeQName,parentNodeRef)
postActivity(activityType,siteId,appTool,nodeRef,name,typeQName,parentNodeRef) this method posts a predefined activity, for example, for the
deleted nodeRef.
Parameters
activityType
Required. Activity type name specified in package format, for example [Link]‐created.
siteId
Required parameter to get site members and to apply feed controls.
appTool
Optional parameter. The application id or component id generating the activity, for example calendarComponent. If set, then feed controls
can be applied.
nodeRef
Required. This allows the activity service to look up some generic data for the node.
name
Optional. The name of node.
typeQName
Optional. The type of node.
parentNodeRef
Optional. Used to look up path/displayPath
setFeedControl
setFeedControl(siteId, appToolId) sets the feed control for a site, an appTool, or a site/appTool combination for the current user.
Parameters
siteId
A string representing the short name of the site. Optional if appToolId is supplied.
appToolId
A string representing the application or component name. Optional if siteId is supplied.
Returns
void
unsetFeedControl
unsetFeedControl(siteId,appTool) unsets the feed control for a site, an appTool, or a site/appTool combination for the current user.
Parameters
siteId
A string representing the short name of the site. Optional if appToolId is supplied.
appToolId
A string representing the application or component name. Optional if siteId is supplied.
Authority service
Authority is a general term to describe a group, user, or role. The authority service provides the following methods to retrieve groups. The
authority service makes the groups root object available.
createRootGroup [194]createRootGroup(shortName,displayName) creates a new root group in the default application zone.
getAllRootGroups [195] The getAllRootGroups() methods return a list of groups found across all zones.
getAllRootGroupsInZone [196] The getAllRootGroupsInZone(zone) methods return a list of groups in the specified zone.
getGroup [197]getGroup(shortName) gets a group given its short name.
getGroupForFullAuthorityName [198]getGroupForFullAuthorityName(fullName) gets a group given its full authority name.
getGroups [199] The getGroups() methods return groups across all zones.
getGroupsInZone [200]getGroupsInZone(...) returns an array of ScriptGroup objects representing groups found in the specified zone.
getUser [201]getUser(username) gets a user given the user's user name.
searchGroups [202] The searchGroups() methods search for groups.
searchGroupsInZone [203] The searchGroupsInZone() methods search for groups in the specified zone.
searchRootGroups [204] The searchRootGroups() methods search for root groups across all zones.
searchRootGroupsInZone [205] The searchRootGroupsInZone() methods search for root groups in the specified zone.
searchUsers [206]searchUsers(nameFilter, paging, sortBy) returns an array of ScriptUsers that match the specified parameters.
ScriptGroup object [207] A ScriptGroup object represents an Alfresco group.
ScriptUser object [208] A ScriptUser object represents an Alfresco user.
createRootGroup
createRootGroup(shortName,displayName) creates a new root group in the default application zone.
Parameters
shortName
A string representing the short name to assign the new group.
displayName
A string representing the display name to assign the new group.
Returns
Returns authority or null if it cannot be found.
Example
var shortName = "MY_GROUP";
var displayName = "MyGroup";
The preceding code snippet would create a new group with the following details:
fullName: GROUP_MY_GROUP
displayName: MyGroup
shortName: MY_GROUP
getAllRootGroups
The getAllRootGroups() methods return a list of groups found across all zones.
Parent topic: Authority service [184]
getAllRootGroups()
getAllRootGroups() this method returns a list groups found across all zones.
Returns
Returns an array of ScriptGroup objects, representing the groups found across all zones.
Example
[Link] = [Link]();
getAllRootGroups(maxItems, skipCount)
getAllRootGroups(maxItems, skipCount) this method returns a list groups found across all zones.
Parameters
maxItems
An integer representing the maximum number of items to return in the results.
skipCount
Integer representing the number of items to skip.
Returns
Returns an array of ScriptGroup objects, representing the groups found across all zones.
Example
[Link] = [Link](5, 0);
getAllRootGroups(paging)
getAllRootGroups(paging) this method returns a list groups found across all zones.
Parameters
paging
A ScriptPagingDetails object.
Returns
Returns an array of ScriptGroup objects, representing the groups found found across all zones.
Example
var paging = [Link](3, 0);
[Link] = [Link](paging);
getAllRootGroupsInZone
The getAllRootGroupsInZone(zone) methods return a list of groups in the specified zone.
Parent topic: Authority service [184]
getAllRootGroupsInZone(zone)
Parameters
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
Returns
Returns an array of ScriptGroup objects, representing the groups found in the specified zone.
Example
[Link] = [Link]("[Link]"); // [Link], [Link], [Link]
getAllRootGroupsInZone(zone, maxItems, skipCount) this method returns a list groups in the specified zone.
Parameters
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
maxItems
An integer representing the maximum number of items to return in the results.
skipCount
Integer representing the number of items to skip.
Returns
Returns an array of ScriptGroup objects, representing the groups found in the specified zone.
Example
[Link] = [Link]("[Link]", 5, 0);
getAllRootGroupsInZone(zone, paging, sortBy) this method returns a list groups in the specified zone.
Parameters
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Returns an array of ScriptGroup objects, representing the groups found in the specified zone.
Example
var paging = [Link](3, 0);
getGroup
getGroup(shortName) gets a group given its short name.
Parameters
shortName
A string representing the short name of the group to return.
Returns
Returns a ScriptGroup object, or null if the group cannot be found.
Example
var shortName = "MY_GROUP";
[Link] = [Link](shortName);
getGroupForFullAuthorityName
getGroupForFullAuthorityName(fullName) gets a group given its full authority name.
Parameters
fullName
A string representing the full authority name of the group to return. This string must start with "GROUP_".
Returns
Returns a ScriptGroup object, or null if the group cannot be found.
Example
var fullName = "GROUP_MY_GROUP";
[Link] = [Link](fullName);
getGroups
The getGroups() methods return groups across all zones.
Parent topic: Authority service [184]
getGroups(filter, paging)
Parameters
filter
Pattern to filter groups by. If the filter is null, an empty string or * all groups found will be returned. If the filter starts with * or contains a ?
character results returned could be inconsistent.
paging
A ScriptPagingDetails object.
Returns
An array of ScriptGroup objects.
Example
var filter = "Star";
getGroups(filter, paging, sortBy) this method returns groups across all zones.
Parameters
filter
Pattern to filter groups by. If the filter is null, an empty string or * all groups found will be returned. If the filter starts with * or contains a ?
character results returned could be inconsistent.
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Example
var filter = "Star";
shortName: Starlight_Title
fullName: GROUP_Admins
shortName: Admins
fullName: GROUP_FINANCE
shortName: FINANCE
fullName: GROUP_STARLIGHT
shortName: STARLIGHT
getGroupsInZone
getGroupsInZone(...) returns an array of ScriptGroup objects representing groups found in the specified zone.
Parent topic: Authority service [184]
getGroupsInZone
getGroupsInZone(filter, zone, paging, sortBy) returns an array of ScriptGroup objects representing groups found in the specified zone.
Attention: Deprecated since 4.0.
Parameters
filter
Pattern to filter groups by. If the filter is null, an empty string or * all groups found will be returned. If the filter starts with * or contains a ?
character results returned could be inconsistent.
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Example
var filter = "Star";
getGroupsInZone
getGroupsInZone(filter, zone, paging, sortBy, sortAsc) returns an array of ScriptGroup objects representing groups found in the specified zone.
Parameters
filter
Pattern to filter groups by. If the filter is null, an empty string or * all groups found will be returned. If the filter starts with * or contains a ?
character results returned could be inconsistent.
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
sortAsc
True to sort results in ascending order, false otherwise.
Returns
Example
var filter = "Star";
getUser
getUser(username) gets a user given the user's user name.
Parameters
username
A string representing the user name of the user.
Returns
Returns a ScriptUser object, or null if the user cannot be found.
Example
var username = "[Link]";
[Link] = [Link](username);
The returned ScriptUser object can be passed to the following FreeMarker template code:
<p>authorityType: ${[Link]}</p>
<p>shortName: ${[Link]}</p>
<p>fullName: ${[Link]}</p>
<p>userName: ${[Link]}</p>
<p>displayName: ${[Link]}</p>
<p>personNodeRef: ${[Link]}</p>
<p>[Link]: ${[Link]}</p>
<p>[Link]: ${[Link]}</p>
The preceding FreeMarker code would display results similar to the following:
authorityType: USER
shortName: [Link]
fullName: [Link]
userName: [Link]
displayName: [Link]
personNodeRef: workspace://SpacesStore/4d7abb60‐d8ff‐4fcf‐956f‐93e53ebafed0
[Link]: 4d7abb60‐d8ff‐4fcf‐956f‐93e53ebafed0
[Link]: {[Link]
searchGroups
The searchGroups() methods search for groups.
Parent topic: Authority service [184]
searchGroups(shortNameFilter)
Parameters
shortNameFilter
A string to filter returned results on the short name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
Returns
Returns an array of ScriptGroup objects that represents the groups matching the query.
searchGroups(shortNameFilter, paging, sortBy) searches for groups based on a short name filter string.
Parameters
shortNameFilter
A string to filter returned results on the short name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Returns an array of ScriptGroup objects that represents the groups matching the query.
Example
// return maximum 3 results, skip 0
var paging = [Link](3, 0);
searchGroupsInZone
The searchGroupsInZone() methods search for groups in the specified zone.
Parent topic: Authority service [184]
searchGroupsInZone(shortNameFilter, zone)
searchGroupsInZone(shortNameFilter, zone) this method searches for groups in the specified zone.
Parameters
shortNameFilter
A string to filter returned results on the short name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
Returns
Returns a ScriptGroup array representing the groups matching the query.
searchGroupsInZone(shortNameFilter, zone, maxItems, skipCount) this method searches for groups in the specified zone.
Parameters
shortNameFilter
A string to filter returned results on the short name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
maxItems
An integer representing the maximum number of items to return in the results.
skipCount
Integer representing the number of items to skip.
Returns
searchGroupsInZone(shortNameFilter, zone, paging, sortBy) this method searches for groups in the specified zone.
Parameters
shortNameFilter
A string to filter returned results on the short name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Returns a ScriptGroup array representing the groups matching the query.
Example
// return maximum 3 results, skip 0
var paging = [Link](3, 0);
searchRootGroups
The searchRootGroups() methods search for root groups across all zones.
Parent topic: Authority service [184]
searchRootGroups(displayNamePattern)
searchRootGroups(displayNamePattern) searches for root groups based on the display name filter string.
Parameters
displayNamePattern
A string to filter returned results on the display name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
Returns
Returns an array of ScriptGroup objects that represents the root groups matching the query.
searchRootGroups(displayNamePattern, paging, sortBy) searches for root groups based on a display name pattern string.
Parameters
displayNamePattern
A string to filter returned results on the display name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Returns an array of ScriptGroup objects that represents the root groups matching the query.
Example
// return maximum 3 results, skip 0
var paging = [Link](3, 0);
searchRootGroupsInZone
The searchRootGroupsInZone() methods search for root groups in the specified zone.
Parent topic: Authority service [184]
searchRootGroupsInZone(displayNamePattern, zone)
searchRootGroupsInZone(displayNamePattern, zone) this method searches for root groups in the specified zone.
Parameters
displayNamePattern
A string to filter returned results on the display name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
Returns
searchRootGroupsInZone(displayNamePattern, zone, maxItems, skipCount) this method searches for root groups in the specified zone.
Parameters
displayNamePattern
A string to filter returned results on the display name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
maxItems
An integer representing the maximum number of items to return in the results.
skipCount
Integer representing the number of items to skip.
Returns
Returns a ScriptGroup array representing the root groups matching the query.
searchRootGroupsInZone(displayNamePattern, zone, paging, sortBy) this method searches for root groups in the specified zone.
Parameters
displayNamePattern
A string to filter returned results on the display name string. Wildcards such as "*" and "?" can be used. When empty string is used, all
results are returned without filtering.
zone
The zone in which to search. This could include application zones such as [Link], [Link], or [Link] or authorization
zones such as [Link] or [Link].<ID>.
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Returns a ScriptGroup array representing the root groups matching the query.
Example
// return maximum 3 results, skip 0
var paging = [Link](3, 0);
searchUsers
searchUsers(nameFilter, paging, sortBy) returns an array of ScriptUsers that match the specified parameters.
Parameters
nameFilter
String to allow a partial match of the name. The user name, first name, and last name will all be checked to see if they start with the filter
string. If empty then the string will match all users.
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Returns an array of ScriptUser objects that represents the users matching the query.
Example
var filterName = "A";
var paging = [Link](‐1, 0);
var sortBy = "userName";
The return results could be displayed using the following FreeMarker template code snippet:
<p>firstName: ${[Link]}</p>
<p>lastName: ${[Link]}</p>
<p>userName: ${[Link]}</p>
<hr/>
</#list>
The preceding code snippet would return results similar to the following:
firstName: Alice
lastName: Beecher
userName: abeecher
firstName: Administrator
lastName:
userName: admin
firstName: Tony
lastName: Tortilla
userName: Archvile
firstName: Peter
lastName: Andrews
userName: petethepiper
ScriptGroup object
A ScriptGroup object represents an Alfresco group.
Properties
authorityType
Get or set the authority type
allGroups
Gets all descendant subgroups
allUsers
Gets the users contained within this group and its subgroups
childUsers
Gets child users of this group
displayName
Get or set the display name for this group (requires administrator permission)
fullName
Get or set the full name of the group
shortName
Get or set the short name of the group
addAuthority
addAuthority(fullAuthorityName) adds an existing authority as a child of this group.
Parameters
fullAuthorityName
A string representing the full name of the authority.
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
createGroup
createGroup(shortName, displayName) creates a new group as a child of this group.
Parameters
shortName
A string representing the short name for the new group.
displayName
A string representing the display name for the new group.
Returns
Returns the new child group.
Example
var shortName = "MY_GROUP";
var group = [Link](shortName);
deleteGroup
deleteGroup() deletes this group.
Parameters
None
Returns
void
Example
var shortName = "MY_TEST_GROUP";
var group = [Link](shortName);
[Link]();
getAllGroups
getAllGroups() returns all descendant groups of this group.
Parameters
None
Returns
An array of ScriptGroup objects.
Example
var groups = [Link]();
getAllParentGroups
The getAllParentGroups() methods return all parent groups of this group.
Parent topic: ScriptGroup object [207]
getAllParentGroups()
Parameters
None
Returns
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
// now find all parent groups
[Link] = [Link]();
getAllParentGroups(maxItems, skipCount)
getAllParentGroups(maxItems, skipCount) this method returns all parent groups of this group.
Parameters
maxItems
An integer representing the maximum number of results to return. If set to 1 all results will be returned.
skipCount
An integer representing the number of results to skip.
Returns
Example
var shortName = "MY_SUB_SUB_GROUP";
var group = [Link](shortName);
getAllParentGroups(paging, sortBy)
getAllParentGroups(paging, sortBy) this method returns all parent groups of this group.
Parameters
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Example
var shortName = "MY_SUB_SUB_GROUP";
var group = [Link](shortName);
getAllUsers
getAllUsers() returns all users contained in this group.
Parameters
None
Returns
An array of ScriptUser objects representing the users contained in this group.
Example
var users = [Link]();
Parent topic: ScriptGroup object [207]
getChildAuthorities
The getChildAuthorities(...) methods return the child authorities (users and groups) of this group.
Parent topic: ScriptGroup object [207]
getChildAuthorities
getChildAuthorities() this method returns the child authorities (users and groups) of this group.
Parameters
None
Returns
Example
var shortName = "MY_GROUP";
var group = [Link](shortName);
[Link] = [Link]();
The following FreeMarker code could be used to display the results from the preceding JavaScript code snippet:
<p>fullName: ${[Link]}</p>
<p>displayName: ${[Link]}</p>
<p>shortName: ${[Link]}</p>
<p>authorityType: ${[Link]}</p>
<hr/>
</#list>
displayName: abeecher
shortName: abeecher
authorityType: USER
fullName: GROUP_ANOTHER_STARLIGHT_GROUP
shortName: ANOTHER_STARLIGHT_GROUP
authorityType: GROUP
fullName: mjackson
displayName: mjackson
shortName: mjackson
authorityType: USER
fullName: GROUP_MY_SUB_GROUP
displayName: MySubGroup
shortName: MY_SUB_GROUP
authorityType: GROUP
fullName: GROUP_FINANCE
shortName: FINANCE
authorityType: GROUP
getChildAuthorities
getChildAuthorities(paging, sortBy) this method returns the child authorities (users and groups) of this group.
Parameters
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Example
var shortName = "MY_GROUP";
var group = [Link](shortName);
The following FreeMarker code could be used to display the results from the preceding JavaScript code snippet:
<p>fullName: ${[Link]}</p>
<p>displayName: ${[Link]}</p>
<p>shortName: ${[Link]}</p>
<p>authorityType: ${[Link]}</p>
<hr/>
</#list>
displayName: abeecher
shortName: abeecher
authorityType: USER
fullName: GROUP_ANOTHER_STARLIGHT_GROUP
shortName: ANOTHER_STARLIGHT_GROUP
authorityType: GROUP
fullName: mjackson
displayName: mjackson
shortName: mjackson
authorityType: USER
fullName: GROUP_MY_SUB_GROUP
displayName: MySubGroup
shortName: MY_SUB_GROUP
authorityType: GROUP
fullName: GROUP_FINANCE
shortName: FINANCE
authorityType: GROUP
getChildGroups
The getChildGroups() methods return child groups of this group.
Parent topic: ScriptGroup object [207]
getChildGroups()
Parameters
None
Returns
Example
var shortName = "MY_GROUP";
var group = [Link](shortName);
getChildGroups(maxItems, skipCount)
Parameters
maxItems
An integer representing the maximum number of results to return. If set to 1 all results will be returned.
skipCount
An integer representing the number of results to skip.
Returns
Example
var shortName = "MY_GROUP";
var group = [Link](shortName);
getChildGroups(paging, sortBy)
getChildGroups(paging, sortBy) this method returns the child groups of this group.
Parameters
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Example
var shortName = "MY_GROUP";
var group = [Link](shortName);
getChildUsers
Parameters
None
Returns
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
getChildUsers
getChildUsers(paging, sortBy) this method gets the child users of this group.
Parameters
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example userName.
Returns
Returns an array of ScriptUser objects.
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
getGroupCount
getGroupCount() returns the number of child groups contained within this group.
Parameters
None
Returns
Returns an integer representing the number of child groups contained within this group.
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
getGroupNode
getGroupNode() returns a script node object wrapping this group.
Parameters
None
Returns
Returns a script node object wrapping this group.
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
getGroupNodeRef
getGroupNodeRef() returns the node reference of this group.
Parameters
None
Returns
Returns a script node object wrapping this group.
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
getParentGroups
The getParentGroups() methods return the immediate parent groups of this group.
Parent topic: ScriptGroup object [207]
getParentGroups()
Parameters
None
Returns
Example
var shortName = "MY_SUB_SUB_GROUP";
var group = [Link](shortName);
getParentGroups(maxItems, skipCount)
getParentGroups(maxItems, skipCount) this method returns immediate parent groups of this group.
Parameters
maxItems
An integer representing the maximum number of results to return. If set to 1 all results will be returned.
skipCount
An integer representing the number of results to skip.
Returns
Example
var shortName = "MY_SUB_SUB_GROUP";
var group = [Link](shortName);
getParentGroups(paging, sortBy)
getParentGroups(paging, sortBy) this method returns the immediate parent groups of this group.
Parameters
paging
A ScriptPagingDetails object.
sortBy
The property by which to sort the results, for example displayName.
Returns
Example
var shortName = "MY_SUB_SUB_GROUP";
var group = [Link](shortName);
getUserCount
getUserCount() returns the number of users within this group.
Parameters
None
Returns
Returns an integer representing the number of users contained within this group.
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
getZones
getZones() returns a set of zone names for this group. Zones provide a higher level way of organizing groups.
Parameters
None
Returns
Returns a set of strings representing the zones of this group.
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
removeAuthority
removeAuthority(fullAuthorityName) removes a child authority from this group.
Parameters
fullAuthorityName
A string representing the full name of the authority.
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
removeGroup
removeGroup(shortName) removes a specified subgroup from this group. It does not delete the subgroup or its members.
Parameters
shortName
A string representing the short name of the sub group to remove from the containing group.
Example
var shortName = "MY_GROUP";
var group = [Link](shortName);
removeUser
The removeUser(shortName) removes a specified child user from this group. It does not delete the user.
Parameters
shortName
The short name of the user to remove.
Example
var shortName = "MY_SUB_GROUP";
var group = [Link](shortName);
ScriptUser object
A ScriptUser object represents an Alfresco user.
Properties
authorityType
Gets or sets the authority type (user, group, role)
displayName
Gets or sets the display name of the user
fullName
Gets or sets the full name of the user
person
Gets the ScriptNode object representing the person
personNodeRef
Gets the nodeRef for the user
shortName
Gets or sets the short name of the user
userName
Gets the user name of the user
getPerson
getPerson() returns a script node wrapping the person.
Parameters
None
Returns
Returns a script node wrapping the person.
Example
var username = "[Link]";
getZones
getZones() returns all the zones of this user.
Parameters
None
Returns
Returns a set of strings representing all the zones of this user.
Example
var username = "[Link]";
Rendition service
A rendition is an alternative representation of a content node. Renditions are derived from their source nodes and are usually updated
automatically when their source node is updated.
Thumbnails are a special case of renditions which are still available through the Thumbnail Service. Other examples include content that has
been transformed into other formats (MIME types), images that have been processed in some way or content which incorporates property
values from the source node. Rendition Services are grouped into the following object types:
Rendition Service
Rendition Definition
createRenditionDefinition
createRenditionDefinition(renditionName, renderingEngineName) creates a new rendition definition with the specified rendition name which uses
the specified rendering engine.
Parameters
renditionName
The rendition definition name. A unique identifier used to specify the created definition.
renderingEngineName
The rendering engine name. The name of the rendering engine associated with this definition.
Returns
Returns the newly created ScriptRenditionDefinition object.
Parent topic: Rendition service [185]
getRenditionByName
getRenditionByName(node, renditionName) retrieves existing renditions for a node by rendition name.
Parameters
node
The source nodes for the renditions.
renditionName
The name used to identify a rendition. For example cm:doclib or {[Link]
Returns
Returns a ScriptNode which represents the parent association for the rendition or null if there is no such rendition.
getRenditions
The getRenditions methods retrieve existing renditions for a node.
Parent topic: Rendition service [185]
getRenditions(node)
Parameters
node
The node whose renditions are requested
Returns
Returns a ScriptNode array of all existing rendition objects for the specified node.
getRenditions(node, mimeTypePrefix)
getRenditions(node, mimeTypePrefix) this method gets renditions for the specified node.
Parameters
node
The node whose renditions are requested
mimeTypePrefix
A filter to restrict the renditions returned to those whose MIMEtype starts with the prefix. This must not be null or an empty string.
Returns
Returns an array of ScriptNode objects representing all existing rendition objects for the specified node whose MIMEtype starts with the given
filter string.
render
The render(...) methods generate a rendition from a specified node.
Parent topic: Rendition service [185]
render(sourceNode, scriptRenditionDef)
render(sourceNode, renditionDefQName) this method uses a rendition definition to produce a rendition from a specified node.
Parameters
sourceNode
The node for which a rendition should be created
scriptRenditionDef
The ScriptRenditionDefinition object to use to render the rendition.
Returns
render(sourceNode, renditionDefQName) this method uses a saved rendition definition to produce a rendition from a specified node.
Parameters
sourceNode
The node for which a rendition should be created
renditionDefQName
The qname of the rendition definition to use for example cm:doclib or {[Link]
Returns
Rendition definition
The ScriptRenditionDefinition extends from ScriptAction and fully specifies a type of rendition. getrenderingEngineName and getRenditionName are
extensions to the existing JavaScript API for script actions.
getRenderingEngineName [234]getRenderingEngineName() retrieves the name of the rendering engine used by the current rendition
definition.
getRenditionName [235]getRenditionName() retrieves the name of the current rendition definition.
getRenderingEngineName
getRenderingEngineName() retrieves the name of the rendering engine used by the current rendition definition.
Returns
Returns the name of the rendering engine used by the current rendition definition.
getRenditionName
getRenditionName() retrieves the name of the current rendition definition.
Returns
Returns the name of this rendition definition in prefix:localName format.
Site service
A site is a collaborative area for a unit of work or a project. Sites are created in Share, and manipulated in various ways directly using the UI or
through web scripts or the REST API.
The methods available for the Site service are grouped into siteService and site object types.
Site service object [236] The siteService object provides methods to create sites, list sites in the repository, list roles that can be assigned
to members of a site, and get sites for given names.
Site object [237] The site object provides site related properties and methods.
cleanSitePermissions
cleanSitePermissions() these methods clean permissions from a node.
When a node is moved or copied from one site to another, the node will retain associated permissions assigned in the source site. These
methods allow any permission from outside of the current site to be removed, so that only the permissions of the containing site will apply to
the specified node.
cleanSitePermissions(ScriptNode targetNode)
cleanSitePermissions(ScriptNode targetNode) cleans permissions from the node specified by the supplied ScriptNode object.
Parameters
targetNode
The target node on which to perform the clean operation.
Returns
void
Example
[Link](node);
cleanSitePermissions(NodeRef targetNode)
cleanSitePermissions(NodeRef targetNode) cleans permissions from the node specified by the supplied nodeRef.
Parameters
targetNode
The node reference of the target node on which to perform the clean operation.
Returns
void
Example
[Link](nodeRef);
createSite
The createSite(...) methods partially create a new site.
CAUTION:
These methods will only create a site at the repository level, and do not create a fully functional site. It should be considered for internal use
only at the moment. You need to create a site programmatically in the Share context, using the create‐site module. Further information can be
found at the address [Link] within your Alfresco installation.
Parent topic: Site service object [236]
createSite
createSite(sitePreset, shortName, title, description, visibility) creates a new site.
CAUTION:
This method only creates a site at the repository level, it does not create a fully functional site. It should be considered for internal use only at
the moment. You need to a site programmatically in the Share context, using the create‐site module. Further information can be found at the
address [Link] within your Alfresco installation.
Parameters
sitePreset
The site preset, for example site‐dashboard or customdefined preset.
shortName
The unique site short name to identify the site
title
A title for the site
description
A description for the site
visibility
The visibility of the site, which is one of siteService.PUBLIC_SITE, siteService.MODERATED_SITE, siteService.PRIVATE_SITE.
Returns
Returns a Site object representing the created site with the specified parameters.
Example
var site = [Link]("site‐dashboard", "gamma‐site", "Gamma Site", "A site description", siteService.PUBLIC_SITE);
createSite
Parameters
sitePreset
The site preset, for example site‐dashboard or customdefined preset.
shortName
The unique site short name to identify the site
title
A title for the site
description
A description for the site
visibility
The visibility of the site, which is one of siteService.PUBLIC_SITE, siteService.MODERATED_SITE, siteService.PRIVATE_SITE.
siteType
QName of site type to create. By default this would be a collaboration site, st:site. It is possible to create other types of site, and these
can be selected here. This value must be a subtype of st:site.
Returns
Returns a Site object representing the created site with the specified parameters.
Example
var site = [Link]("site‐dashboard", "gamma‐site", "Gamma Site", "A site description", siteService.PUBLIC_SITE, "st:site");
findSites
findSites(filter, sitePresetFilter, size) searches for and returns a list of sites. The returned list can be optionally filtered by name and site
preset. If no filters are specified then all the available sites are returned.
This method will find all sites available to the currently authenticated user based on the specified site filter, site preset filter and result set size.
The filter parameter will match any sites whose cm:name, cm:title, cm:description contain the specified string (ignoring case). Note that this
method uses Alfresco Full Text Search [249] to retrieve results and depending on SOLR configuration can only offer eventually consistent results.
Parameters
filter
An inclusion filter string for returned sites. Any supplied filter will be wrapped in asterisks, for example as in '*foo*', and used to match
sites whose cm:name, cm:title, or cm:description contains the filter string.
sitePresetFilter
Site preset filter name to match against.
size
The maximum number of results to return. The default, 0, returns all results.
Returns
Returns a list of Site objects. The list can be empty, but not null.
Example
The following code snippet will search for all sites that contain 'foo' in their name, title or description:
var sites = [Link]('foo', null, 0);
getSite
getSite(shortName) gets a site for a provided short name.
Parameters
shortName
The short name of the site
Returns
Return a site object, or returns null if the site does not exist.
Example
var site = [Link]("simple‐site");
if(site){
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
}
getSites
getSites(filter, sitePresetFilter, size) returns a list of sites. Retrieves all the sites available in the repository. The returned list can optionally
be filtered by name and site preset. If no filters are specified then all the available sites are returned.
If filters start with a "*" character, a Solrbased search will be performed, rather than a database query. This can discover a wider range of
results, such as those sites that contain the search term, as opposed to those that start with the search term.
Within the implementation of this method, if the query does not contain a wildcard, then listSites() is invoked, else findSites() is used instead.
Note: When using Solr searches, rather than direct database queries, newly created sites might not be found until the underlying search
indexes are updated.
Parameters
filter
An inclusion filter string for returned sites. Only sites whose cm:name, cm:title, or cm:description start with the filter string will be returned.
sitePresetFilter
Site preset filter string.
size
The maximum number of results to return. The default, 0, returns all results.
Returns
Returns a list of Site objects. The list can be empty, but not null.
Example
The following code snippet will return all sites:
hasCreateSitePermissions
hasCreateSitePermissions() returns true if the currently logged on user has permission to create a site.
Returns
Returns a boolean. Returns true if the currently authenticated user has permission to create a site, false otherwise.
Example
var result = [Link]();
hasSite
hasSite(String shortName) returns true if the specified site exists. Allows private site existence to be tested.
Returns
Returns a boolean. Returns true if specified site exists, false otherwise.
Example
var result = [Link]();
isSiteManager
isSiteManager(siteId) checks whether the currently authenticated user is a site manager or not, for the specified site.
Parameters
siteId
The short name of the site to check.
Returns
Returns a boolean. True is returned if the currently authenticated user is a site manager, false otherwise.
Example
result = [Link]("simple‐site");
listSiteRoles
The listSiteRoles() methods list all the roles that can be assigned to a member of a site.
Parent topic: Site service object [236]
listSiteRoles
listSiteRoles() lists all the roles that can be assigned to a member of a site.
Returns
Returns an array containing strings representing the roles available to assign to a member of a site.
Example
var roles = [Link]();
The preceding code snippet would return a list of roles such as:
SiteManager
SiteCollaborator
SiteContributor
SiteConsumer
listSiteRoles(shortName)
listSiteRoles(shortName) lists all the roles that can be assigned to a member of a site, for a specific site.
Parameters
shortName
A string representing the short name of the site to list roles for.
Returns
Returns an array containing strings representing the roles available to assign to a member of a site.
Example
var roles = [Link]("test‐site");
The preceding code snippet would return a list of roles for the specified site, such as:
SiteManager
SiteCollaborator
SiteContributor
SiteConsumer
listSites
The listSites methods list the sites that are available in the repository.
List the available sites. This list can optionally be filtered by site name/title/description and/or site preset. This method uses a database query
rather than using Solr.
Note: Starting with Alfresco 4.0, the filter parameter will only match sites whose cm:name or cm:title or cm:description starts with the specified
string (ignoring case). The listing of sites whose cm:names (or titles or descriptions) contain the specified string is no longer supported. To
retrieve sites whose cm:names (or titles or descriptions) contain a substring, findSites(String, String, int) should be used instead.
Parent topic: Site service object [236]
listSites(nameFilter, sitePresetFilter)
listSites(nameFilter, sitePresetFilter) lists the sites that are available in the repository.
Parameters
nameFilter
String by which to filter the list of sites returned. Only sites whose cm:name or cm:title or cm:description start with the filter string will be
returned.
sitePresetFilter
The site preset filter (sites whose preset EQUALS sitePresetFilter).
Returns
A list of the sites filtered, as appropriate. If no filters are specified then all the available sites are returned.
listSites(nameFilter, sitePresetFilter, size) lists the sites that are available in the repository.
Parameters
nameFilter
String by which to filter the list of sites returned. Only sites whose cm:name or cm:title or cm:description starts with the filter string will be
returned.
sitePresetFilter
The site preset filter.
size
The maximum number of sites to return. By default this is set to 0, which returns all results.
Returns
A list of the sites filtered, as appropriate. If no filters are specified then all the available sites are returned.
Example
The following code snippet would return all sites without any filtering or restriction on number of results returned:
var sites = [Link](null, null, 0);
The following code snippet would return all dashboard sites whose name, title or description starts with the text "test" and restricts the number
of sites returned to 5:
var sites = [Link]("test", null, 5);
listUserSites
The listUserSites() methods list all the sites to which the specified user has an explicit membership.
Parent topic: Site service object [236]
listUserSites
listUserSites(userName) lists all the sites to which the specified user has an explicit membership.
Parameters
userName
The user name for the user whose site membership is to be listed.
Returns
Returns a list of the sites to which the specified user has an explicit membership.
Example
var sites = [Link]("admin");
listUserSites
listUserSites(userName, size) lists all the sites to which the specified user has an explicit membership.
Parameters
userName
The user name for the user whose site membership is to be listed.
size
An integer representing the number of results to return. The default is 0 which returns all results.
Returns
Returns a list of the sites to which the specified user has an explicit membership.
Example
var sites = [Link]("admin", 10);
Site object
The site object provides site related properties and methods.
Properties
description
The displayable description of the site.
isPublic
Whether the site is public or not (true or false).
node
The site node (null if there are none).
shortName
A readonly unique short name identifying the site.
siteGroup
The site group name.
sitePermissionGroups
A map of role name mapped to associated group name.
sitePreset
A readonly name of the site preset used to create the site.
title
The displayable title of the site.
visibility
The visibility of the site (PUBLIC_SITE, MODERATED_SITE, PRIVATE_SITE)
Example
var site = [Link]("simple‐site");
if(site){
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
}
acquireContainer [250]acquireContainer(...) gets and, if missing, creates a new site container. The container is created in a new
read/write transaction.
createAndSaveContainer [251]createAndSaveContainer(containerId, containerType, description) indicates whether a user is a member of
the site.
createContainer [252] The createContainer methods create new site containers.
deleteSite [253]deleteSite() deletes a site.
getContainer [254]getContainer(componentId) gets (or creates) the container folder (node) folder for the specified component identifier with
the container type cm:folder.
getCustomProperties [255]getCustomProperties() gets a map of the custom properties of the site.
getCustomProperty [256]getCustomProperty(name) gets the value of a custom property (null if the custom property has not been set or does
not exist).
getInvitation [257]getInvitation(invitationId) gets an invitation to this web site.
getMembersRole [258]getMembersRole(authorityName) returns a user's role in this site.
getMembersRoleInfo [259]getMembersRoleInfo(authorityName) returns extended information about a user's role in this site.
hasContainer [260]hasContainer(componentId) determines if the container folder for the specified component exists; if true the container
folder exists.
inviteModerated [261]inviteModerated(inviteeComments, inviteeUserName, inviteeRole) creates a new moderated invitation to the specified
web site.
inviteNominated (new user) [262]inviteNominated(inviteeFirstName, inviteeLastName, inviteeEmail, inviteeRole, acceptUrl, rejectUrl)
creates a new nominated invitation to this web site for a new user who might not already be an Alfresco user.
inviteNominated (existing user) [263]inviteNominated(inviteeUserName, inviteeRole, acceptUrl, rejectUrl) creates a new nominated
invitation to this web site for an existing user.
isMember [264]isMember(authorityName) indicates whether a user is a member of the site.
isMemberOfGroup [265]isMemberOfGroup(authorityName) indicates whether a user belongs to a group that has access rights to the site.
listInvitations [266]listInvitations() lists the outstanding invitations for this web site.
listMembers [267]listMembers(nameFilter, roleFilter, size, collapseGroups) gets a map of members of the site filtered by user name
and/or user role.
removeMembership [268]removeMembership(authorityName) removes the specified user from a web project.
resetAllPermissions [269]resetAllPermissions(node) resets any permissions that have been set on the node, deleting all permissions and
setting the node to inherit permissions.
save [270]save() saves any outstanding updates to the site detail. Those changes will be lost if properties of the site change and the save
method is not called.
setMembership [271]setMembership(authorityName, role) sets the membership details for a user.
setPermissions [272]setPermissions(node, permissions) sets permissions for a node.
acquireContainer
acquireContainer(...) gets and, if missing, creates a new site container. The container is created in a new read/write transaction.
Parent topic: Site object [237]
acquireContainer
acquireContainer(String componentId) gets and if missing creates a new site container. The container is created in a new read/write transaction.
Parameters
component ID
A string specifying the component ID.
Returns
acquireContainer
acquireContainer(String componentId, String folderType) gets and if missing creates a new site container. The container is created in a new
read/write transaction.
Parameters
componentId
A string specifying the component ID.
folderType
The folder type to create.
Returns
A ScriptNode object representing the newly created container.
acquireContainer
acquireContainer(String componentId, String folderType, Object properties) gets and if missing creates a new site container. The container is
created in a new read/write transaction.
Parameters
componentId
A string specifying the component ID.
folderType
The folder type to create.
properties
The properties to set on the container.
Returns
createAndSaveContainer
createAndSaveContainer(containerId, containerType, description) indicates whether a user is a member of the site.
Parameters
containerId
A string specifying the id for the container node.
containerType
A string specifying the type for the container node.
description
A string specifying a value for the cm:description property on the container node.
Returns
A ScriptNode object representing the newly created and saved container.
createContainer
The createContainer methods create new site containers.
Parent topic: Site object [237]
createContainer
Parameters
componentId
The component identifier
createContainer
The createContainer(componentId, folderType) method creates a new site container of the given type (type of container of subtype of cm:folder).
Parameters
componentId
The component identifier
folderType
The type of folder to create. If this is null, it creates a standard folder.
createContainer
The createContainer(componentId, folderType, permissions) method creates a new site container of the given type and applies the provided
permissions (a map of authorities and permissions) to the created container.
Parameters
componentId
The component identifier
folderType
The type of folder to create. If this is null, it creates a standard folder.
permissions
The permissions for the site.
deleteSite
deleteSite() deletes a site.
Example
var site = [Link]("site‐to‐delete");
if(site){
[Link]();
site = [Link]("site‐to‐delete");
if(!site){
[Link] = "Site not found!";
}
else{
[Link] = "Site found!";
}
}
getContainer
getContainer(componentId) gets (or creates) the container folder (node) folder for the specified component identifier with the container type
cm:folder.
The type of container is either the one specified by the caller (which must be cm:folder or a subtype of), or cm:folder, if a type is not specified at
all.
Parameters
componentId
The component identifier
Returns
Returns a ScriptNode object representing the container folder, or null if the container cannot be returned or created (mostl likely due to
permissions).
getCustomProperties
getCustomProperties() gets a map of the custom properties of the site.
Returns
Returns a map of property names and values.
getCustomProperty
getCustomProperty(name) gets the value of a custom property (null if the custom property has not been set or does not exist).
Parameters
name
The QName of the property.
Returns
Returns the value of the property, or null if not set.
getInvitation
getInvitation(invitationId) gets an invitation to this web site.
Parameters
invitationId
The invitation id of the invitation to return.
Returns
The ScriptInvitation object.
Parent topic: Site object [237]
getMembersRole
getMembersRole(authorityName) returns a user's role in this site.
Parameters
authorityName
A string representing the authority name.
Returns
Returns a string representing the user's role or null if not a member.
Example
The following code snippet uses getMembersRole to determine the site role of the authority "admin":
var site = [Link]("swsdp");
if(site){
if([Link](authorityName)){
[Link] = authorityName;
[Link] = [Link](authorityName);
}
}
getMembersRoleInfo
getMembersRoleInfo(authorityName) returns extended information about a user's role in this site.
Parameters
authorityName
A string representing the authority name.
Returns
Returns a SiteMemberInfo object describing the user's role, or null if the user is not a member.
Example
The following code snippet uses getMembersRoleInfo to determine the site role of the authority "admin":
var site = [Link]("swsdp");
if(site){
if([Link](authorityName)){
[Link] = authorityName;
[Link] = [Link](authorityName);
}
}
hasContainer
hasContainer(componentId) determines if the container folder for the specified component exists; if true the container folder exists.
Parameters
componentId
The component to check for existence of a container folder.
Returns
Returns a boolean, true if container folder exists, false otherwise.
inviteModerated
The inviteModerated(inviteeComments, inviteeUserName, inviteeRole) creates a new moderated invitation to the specified web site.
Parameters
inviteeComments
String.
inviteeUserName
String.
inviteeRole
String.
Returns
A ScriptInvitation object.
Parameters
inviteeFirstName
A string representing the invited user's first name.
inviteeLastName
A string representing the invited user's last name.
inviteeEmail
A string representing the invited user's email address.
inviteeRole
A string representing the invited user's role, for example: Manager, Collaborator, Contributor, Consumer.
acceptUrl
A string representing the URL corresponding to acceptance of the invitation.
rejectUrl
A string representing the URL corresponding to rejection of the invitation.
Returns
A ScriptInvitation object.
Parameters
inviteeUserName
A string representing the invitee's user name.
inviteeRole
A string representing the invited user's role, for example: Manager, Collaborator, Contributor, Consumer.
acceptUrl
A string representing the URL corresponding to acceptance of the invitation.
rejectUrl
A string representing the URL corresponding to rejection of the invitation.
Returns
A ScriptInvitation object.
isMember
isMember(authorityName) indicates whether a user is a member of the site.
Parameters
authorityName
A string representing the user's authority name.
Returns
Boolean
Example
The following code snippet uses isMember to test if "admin" is a member of the site "swsdp":
var site = [Link]("swsdp");
if(site){
if([Link](authorityName)){
[Link] = authorityName;
[Link] = [Link](authorityName);
}
}
isMemberOfGroup
isMemberOfGroup(authorityName) indicates whether a user belongs to a group that has access rights to the site.
Parameters
authorityName
A string representing the user's authority name.
Returns
Boolean
This is true if the user is a member of a group that has access to this site, or false if otherwise.
Example
The following code snippet uses isMemberOfGroup to test if "[Link]" is a member of a group that has access to the site "swsdp":
var site = [Link]("swsdp");
if(site){
if([Link](authorityName)){
...
}
}
listInvitations
listInvitations() lists the outstanding invitations for this web site.
Returns
An array of ScriptInvitation objects.
listInvitations(props)
listInvitations(props) this method lists the open invitations for this web site.
Parameters
props
The optional properties to search for, such as inviteeUserName and invitationType.
Returns
An array of ScriptInvitation objects.
listMembers
listMembers(nameFilter, roleFilter, size, collapseGroups) gets a map of members of the site filtered by user name and/or user role.
If no name or role filter is specified all members of the site are listed.
This list includes both users and groups if collapseGroups is set to false, otherwise all groups that are members are collapsed into their
component users and listed.
Parameters
nameFilter
User name filter string.
roleFilter
User role filter string.
size
Limit the return results to this number of items. The default, 0, returns all results.
collapseGroups
True if collapse member groups into user list; false otherwise.
Returns
Returns the list of members of a site with their roles or all site members if no name or role filter is specified.
Example
The following code snippet would return all members with no filtering, and the members of groups are also collapsed into the member list
returned:
removeMembership
removeMembership(authorityName) removes the specified user from a web project.
Parameters
authorityName
A string representing the user name of the user to remove from membership of the site.
Returns
void
Example
var site = [Link]("swsdp");
if(site){
[Link](authorityName);
...
}
resetAllPermissions
resetAllPermissions(node) resets any permissions that have been set on the node, deleting all permissions and setting the node to inherit
permissions.
Parameters
node
The ScriptNode object for which to reset all permissions.
Returns
void
save
save() saves any outstanding updates to the site detail. Those changes will be lost if properties of the site change and the save method is not
called.
Example
var site = [Link]("simple‐site");
if(site){
[Link] = oldDescription;
[Link] = [Link];
}
setMembership
setMembership(authorityName, role) sets the membership details for a user.
If the user is not already a member of the site, then they are added with the role given. If the user is already a member of the site, then their
role is updated to the new role.
Only a site manager can modify memberships. There must be at least one site manager at all times.
Parameters
authorityName
A string representing the user's user name.
role
A string representing the role for the user.
Example
var site = [Link]("swsdp");
if(site){
[Link](authorityName, role);
...
setPermissions
setPermissions(node, permissions) sets permissions for a node.
Parameters
node
The ScriptNode object to set permissions for.
permissions
The permissions to set for the object.
Tagging service
A tag is a nonhierarchical keyword or term assigned to a piece of information. The root object used to access these services is taggingService.
You must enable the auditing service and the tag audit application for taggingService to function properly. Set [Link]=true and
[Link]=true in the application configuration.
createTag
createTag(store, tag) creates a node representing the tag.
Parameters
store
A store reference string designating the store in which to create the tag.
tag
A string designating the tag to create.
Returns
A ScriptNode object corresponding to the created tag. Null if the tag can not be created.
Example
[Link] = [Link]("workspace://SpacesStore", "cloud");
Parent topic: Tagging service [187]
deleteTag
deleteTag(store, tag) deletes the specified tag.
Parameters
store
A store reference string designating the store in which the tag is located.
tag
A string designating the tag to delete.
Returns
void
Example
if([Link]("workspace://SpacesStore", "cloud")){
[Link]("workspace://SpacesStore", "cloud");
model.message1 = "Tag successfully deleted!";
}
else {
model.message1 = "Tag does not exist!";
}
// ensure deleted
if([Link]("workspace://SpacesStore", "cloud")){
model.message2 = "Tag found!";
}
else {
model.message2 = "Tag does not exist!";
}
The preceding code snippet would result in the following messages if the tag was found and deleted:
Message1: Tag successfully deleted!
getTag
getTag(store, tag) returns a tag node for the specified store and tag.
Parameters
store
A store reference string designating the store to scan for tags.
tag
A string designating the tag to fetch.
Returns
A ScriptNode object corresponding to the specified tag. Null if tag not found.
Example
[Link] = [Link]("workspace://SpacesStore", "cold");
The preceding code snippet would return a node for the tag "cold". The node details can be displayed using the following FreeMarker template
code:
getTags
The getTags() methods get all the tags available in a store.
Parent topic: Tagging service [187]
getTags(store)
Parameters
store
A store reference string designating the store to scan for tags.
Returns
Example
The following code snippet would return all tags in the SpacesStore:
[Link] = [Link]("workspace://SpacesStore");
The following FreeMarker template code could then enumerate the tags:
getTags(store, filter)
Parameters
store
A store reference string designating the store to scan for tags.
filter
A string used to filter the list of returned tags.
Returns
Example
The following code snippet would return tags in the SpacesStore which contained the text "co":
[Link] = [Link]("workspace://SpacesStore", "co");
TagScope object
The taggingrelated ScriptNode methods such as getTagScope return TagScope objects.
Properties
The TagScope object type provides the following property:
tags
A readonly array containing the tag details in count order.
getCount [278]getCount(tag) gets the count of a tag; that is, how many times the tag is used within the tag scope. This is zero if the tag is
not present.
getTopTags [279]getTopTags(topN) gets the top tags ordered by count.
refresh [280]refresh() refreshes the tag scope, causing the tags and counts within the tag scope to be updated.
getCount
getCount(tag) gets the count of a tag; that is, how many times the tag is used within the tag scope. This is zero if the tag is not present.
Parameters
tag
A string representing the tag to return the count for.
Example
The following code snippet would return the count for the tag "cool":
var node = [Link]("TAG_SCOPE_FOLDER/TEST_FILE_1.TXT");
if (node){
getTopTags
getTopTags(topN) gets the top tags ordered by count.
Parameters
topN
The number of top tags to return.
Returns
Returns the top tag details ordered by count.
Example
var node = [Link]("TAG_SCOPE_FOLDER/TEST_FILE_1.TXT");
if (node){
The preceding code snippet would return results for tags and topTags such as the following:
Node found
Tags:
Top tags:
refresh
refresh()refreshes the tag scope, causing the tags and counts within the tag scope to be updated.
Parent topic: TagScope object [277]
Thumbnail service
A thumbnail is a transformation of content into a specified destination MIME type. This is most commonly an image of a particular size, but can
also be other things, for example, a Flash rendition. The Thumbnail service transforms and maintains this thumbnail.
getMimeAwarePlaceHolderResourcePath
getMimeAwarePlaceHolderResourcePath(thumbnailName, mimetype) gets the resource path for the place holder thumbnail for the given named
thumbnail and the given mime type.
If there is no icon available for the specified MIME type, a generic icon will be used instead. The generic icon is that returned by
getPlaceHolderResourcePath(String). If neither a MIMEspecific icon nor a generic icon is available, null is returned.
Parameters
thumbnailName
A string representing the thumbnail name.
mimetype
A string representing the mimetype of the piece of content.
Returns
Returns a string of placeholder thumbnail resource path (null if it is not set).
Parent topic: Thumbnail service [188]
getPlaceHolderResourcePath
getPlaceHolderResourcePath(thumbnailName) gets the resource path for the place holder thumbnail for the given named thumbnail.
Parameters
thumbnailName
A string representing the thumbnail name.
Returns
Returns a string of placeholder thumbnail resource path (null if it is not set).
Parent topic: Thumbnail service [188]
isThumbnailNameRegistered
isThumbnailNameRegistered(thumbnailName) determines whether a given thumbnail name has been registered.
Parameters
thumbnailName
A string representing the thumbnail name.
Returns
Returns true if the thumbnail name is registered. Otherwise it returns false.
Parent topic: Thumbnail service [188]
Workflow service
The Workflow JavaScript API lets you access Alfresco advanced workflows from within JavaScript.
This API provides the ability to:
Access and manage workflow definitions, instances, paths, tasks, and transitions
Create workflow packages
Start, cancel, or delete workflow instances
End and progress workflow paths to the next node with a specified transition
Note: The object model for this API is similar to that of the Advanced Workflow Java API. The relationships between the various types used in
this API are the same as the relationships between the various classes used in the Advanced Workflow API. Each class in the Workflow
JavaScript API mirrors a class in the Advanced Workflow API, however, the JavaScript classes are simpler, making them more easily
accessible from JavaScript. All the JavaScript classes implement the Serializable interface, which allows them to be stored in Scriptable
objects.
JscriptWorkflowDefinition [284] The workflow definition is the type (or template) of a workflow process. A workflow process definition
relates to a workflow instance like a Java class definition relates to an instance of that class. You can use the workflow definition to create
and start new workflow instances of that type, as well as to find all currently active instances of that type.
JscriptWorkflowInstance [285] The workflow instance holds various data about a workflow such as its start date, due date, current state,
and so on. A workflow instance can be cancelled (made inactive), or deleted.
JscriptWorkflowNode [286] A workflow node is a single point in the workflow process. Some workflow nodes are task nodes with
associated tasks that must be completed before the workflow can transition to the next node.
JscriptWorkflowPath [287] The workflow path represents the current state (position) of a workflow instance.
JscriptWorkflowTask [288] JscriptWorkflowTask represents a specific instance of a workflow task as opposed to a workflow task definition
(the task type). A workflow task instance represents a user action, which is usually something that cannot be automated in the workflow.
JscriptWorkflowTransition [289] The workflow transition is a simple Data Transfer Object (DTO) representing a single transition type.
Workflow Manager [290] The Workflow Manager is the entry point to the Workflow JavaScript API. It is the only object in this API exposed
to the root scripting scope. In the root scripting scope, the WorkflowManager object is identified as workflow.
JscriptWorkflowDefinition
The workflow definition is the type (or template) of a workflow process. A workflow process definition relates to a workflow instance like a Java
class definition relates to an instance of that class. You can use the workflow definition to create and start new workflow instances of that type,
as well as to find all currently active instances of that type.
Properties
id
Returns an ID for this workflow definition
name
Returns a string name for this workflow definition
version
Returns a version number for this workflow definition
title
Returns a title for this workflow definition
description
Returns a description for this workflow definition
activeInstances
Returns an array of all active workflow instances for this workflow definition.
startWorkflow [291] The startWorkflow() methods create and start a new workflow instance of the workflow definition type.
startWorkflow
The startWorkflow() methods create and start a new workflow instance of the workflow definition type.
Parent topic: JscriptWorkflowDefinition [284]
startWorkflow(properties)
startWorkflow(properties) this method creates and starts a new workflow instance of the workflow definition's type.
Parameters
properties
If not of type ScriptableObject, the properties parameter will be ignored
Returns
Returns the workflow path (JscriptWorkflowPath) for the created instance. This method does not set a package container.
startWorkflow(workflowPackage, properties)
startWorkflow(properties) this method creates and starts a new workflow instance of the workflow definition's type.
Parameters
workflowPackage
Workflow package node to attach to the new workflow.
properties
If not of type ScriptableObject, the properties parameter will be ignored
Returns
Returns the workflow path (JscriptWorkflowPath) for the created instance.
JscriptWorkflowInstance
The workflow instance holds various data about a workflow such as its start date, due date, current state, and so on. A workflow instance can
be cancelled (made inactive), or deleted.
Properties
active
Returns true if the workflow instance is in progress, or false otherwise
description
Returns the description for this workflow instance
endDate
Returns the date when this workflow instance ended
id
Returns the ID for this workflow instance
paths
Returns an array containing all the paths associated with this workflow instance
startDate
Returns the date when this workflow instance started
remove
remove()removes the workflow instance.
Parent topic: JscriptWorkflowInstance [285]
JscriptWorkflowNode
A workflow node is a single point in the workflow process. Some workflow nodes are task nodes with associated tasks that must be completed
before the workflow can transition to the next node.
Properties
description
Returns the description for this workflow node
isTaskNode
Returns true if this node is a task node, or false otherwise
name
Returns the name when this workflow node
title
Returns the title for this workflow node
transitions
Returns the list of transitions that are available for this node
JscriptWorkflowPath
The workflow path represents the current state (position) of a workflow instance.
The path stores the current position in the workflow as well as the path taken through the workflow to reach this point. An inprogress workflow
can have multiple workflow paths if the process contains any forking nodes. The workflow path can be signaled to transition to the next node in
the process.
Properties
active
Returns true if this node is a task node, or false otherwise
id
Returns the ID for this workflow path
instance
Returns the workflow instance to which this workflow path belongs
node
Returns the current node (position) of the workflow path
tasks
Returns an array of all the tasks associated with this workflow path
signal [294]signal(transitionId) signals the workflow path to transition to the next node.
signal
signal(transitionId) signals the workflow path to transition to the next node.
Parameters
transitionId
ID of the transition to follow (or null, for the default transition)
Returns
Returns JscriptWorkflowPath object representing the newly transitioned workflow path
Parent topic: JscriptWorkflowPath [287]
JscriptWorkflowTask
JscriptWorkflowTask represents a specific instance of a workflow task as opposed to a workflow task definition (the task type). A workflow task
instance represents a user action, which is usually something that cannot be automated in the workflow.
Task instances can be associated with workflow nodes within the process definition. When the workflow path reaches a node with an
associated task, it will not progress until the task is complete and the user signals a transition. A workflow task instance can be signaled with a
transition causing the workflow path to progress to the next node with the specified transition.
Some typical examples of where tasks might be used include reviewing and approving documents, editing and appending documents, and
marking exam papers.
Properties
complete
Returns whether the task is complete or not. True means the task is complete, false not complete.
description
Returns the description for the workflow task instance
id
Returns the ID for the workflow task instance
name
Returns the name for the workflow task instance
packageResources
Returns an array of NodeRefs of the content stored in the package container associated with this workflow task instance
pooled
Gets or sets if this is a pooled task instance or not (true or false). A pooled task instance can be assigned to a group of users, of which
one can take ownership and progress the task
properties
Gets or sets a map containing all the properties associated with this task instance
title
Returns the title for the workflow task instance
transitions
Returns a map containing all the transition IDs (map keys) and transition titles (map values) for the task instance
endTask [295]endTask(transitionId) ends the task and signals the associated workflow path to progress to the next node using the
specified transition.
endTask
endTask(transitionId) ends the task and signals the associated workflow path to progress to the next node using the specified transition.
Parameters
transitionId
ID of the transition to end the task for.
Returns
void
JscriptWorkflowTransition
The workflow transition is a simple Data Transfer Object (DTO) representing a single transition type.
Properties
description
Returns the description for the workflow transition
id
Returns the ID for the workflow transition
title
Returns the title for the workflow transition
Properties
allDefinitions
Returns an array of all (old and current) versions of deployed workflow definitions For current versions only, use latestDefinitions.
assignedTasks
Returns an array of all tasks that are currently in progress assigned to the current user.
completedTasks
Returns an array of all completed tasks assigned to the current user.
latestDefinitions
Returns an array of the latest version of all deployed workflow definitions For all versions, use allDefinitions.
createPackage [296]createPackage() creates a package. A package is a container node that can store content associated with a workflow
instance.
getAllDefinitions [297]getAllDefinitions() Returns all versions of the deployed workflow definitions.
getAssignedTasks [298]getAssignedTasks() Get tasks assigned to the current user. Note that this will only return inprogress tasks.
getCompletedTasks [299]getCompletedTasks() Get completed tasks assigned to the current user.
getDefinition [300]getDefinition(id) returns a workflow definition with the specified ID.
getDefinitionByName [301]getDefinitionByName(name) gets the workflow definitions corresponding to the specified name.
getInstance [302]getInstance(workflowInstanceId) gets the workflow instance with the specified ID.
getLatestDefinitions [303]getLatestDefinitions() Gets the latest versions of the deployed, workflow definitions.
getPooledTasks [304]getPooledTasks(authority) gets pooled workflow task instances available to the given authority.
getTask [305]getTask(id) returns the workflow task instance with the specified ID.
getTaskById [306]getTaskById(id) returns the workflow task instance with the specified ID.
createPackage
createPackage() creates a package. A package is a container node that can store content associated with a workflow instance.
Returns
Returns a ScriptNode object corresponding to the created container.
getAllDefinitions
getAllDefinitions() Returns all versions of the deployed workflow definitions.
Parameters
None
Returns
Returns all versions of the deployed workflow definitions.
Example
[Link] = [Link]();
getAssignedTasks
getAssignedTasks() Get tasks assigned to the current user. Note that this will only return inprogress tasks.
Parameters
None
Returns
Returns the list of assigned (inprogress) tasks.
Example
[Link] = [Link]();
getCompletedTasks
getCompletedTasks() Get completed tasks assigned to the current user.
Parameters
None
Returns
Returns the list of completed tasks.
Example
[Link] = [Link]();
getDefinition
getDefinition(id) returns a workflow definition with the specified ID.
Parameters
id
A string representing the ID of the workflow definition.
Returns
Returns the workflow definition with the given ID. Returns null if no workflow definition with the given ID exists.
Example
var id = "activiti$activitiAdhoc:1:4";
[Link] = [Link](id);
getDefinitionByName
getDefinitionByName(name) gets the workflow definitions corresponding to the specified name.
Parameters
name
A string representing the name of the workflow definition to return.
Returns
Returns the workflow definition with the given name or null if no workflow definition with the given name exists.
Example
var name = "activiti$activitiAdhoc";
[Link] = [Link](name);
getInstance
getInstance(workflowInstanceId) gets the workflow instance with the specified ID.
Parameters
workflowInstanceId
A string representing the ID of the workflow instance.
Returns
Returns the workflow instance with the given ID or null if no workflow instance with the given ID exists.
Example
var id = "activiti$164";
[Link] = [Link](id);
getLatestDefinitions
getLatestDefinitions() Gets the latest versions of the deployed, workflow definitions.
Parameters
None
Returns
Returns the latest versions of the deployed, workflow definitions.
Example
[Link] = [Link]();
getPooledTasks
getPooledTasks(authority) gets pooled workflow task instances available to the given authority.
A pooled task can be assigned to a group of users, and then one of those users may take ownership and progress the task.
Parameters
authority
Returns
Returns an array of the pooled workflow task instances available to the given authority.
Example
[Link] = [Link]("GROUP_SUPERUSERS");
getTask
getTask(id) returns the workflow task instance with the specified ID.
Parameters
id
The ID of the workflow task instance.
Returns
Returns the workflow task instance with the specified ID. Returns null if no workflow task instance with the given ID exists.
Example
var taskId = "activiti$144";
[Link] = [Link](taskId);
getTaskById
getTaskById(id) returns the workflow task instance with the specified ID.
Parameters
id
The ID of the workflow task instance.
Returns
Returns the workflow task instance with the specified ID. Returns null if no workflow task instance with the given ID exists.
Example
var taskId = "activiti$144";
[Link] = [Link](taskId);
Links:
[1] [Link]
[2] [Link]
[3] [Link]
[4] [Link]
[5] [Link]
[6] [Link]
[7] [Link]
[8] [Link]
[9] [Link]
[10] [Link]
[11] [Link]
[12] [Link]
[13] [Link]
[14] [Link]
[15] [Link]
[16] [Link]
[17] [Link]
[18] [Link]
[19] [Link]
[20] [Link]
[21] [Link]
[22] [Link]
[23] [Link]
[24] [Link]
[25] [Link]
[26] [Link]
[27] [Link]
[28] [Link]
[29] [Link]
[30] [Link]
[31] [Link]
[32] [Link]
[33] [Link]
[34] [Link]
[35] [Link]
[36] [Link]
[37] [Link]
[38] [Link]
[39] [Link]
[40] [Link]
[41] [Link]
[42] [Link]
[43] [Link]
[44] [Link]
[45] [Link]
[46] [Link]
[47] [Link]
[48] [Link]
[49] [Link]
[50] [Link]
[51] [Link]
[52] [Link]
[53] [Link]
[54] [Link]
[55] [Link]
[56] [Link]
[57] [Link]
[58] [Link]
[59] [Link]
[60] [Link]
[61] [Link]
[62] [Link]
[63] [Link]
[64] [Link]
[65] [Link]
[66] [Link]
[67] [Link]
[68] [Link]
[69] [Link]
[70] [Link]
[71] [Link]
[72] [Link]
[73] [Link]
[74] [Link]
[75] [Link]
[76] [Link]
[77] [Link]
[78] [Link]
[79] [Link]
[80] [Link]
[81] [Link]
[82] [Link]
[83] [Link]
[84] [Link]
[85] [Link]
[86] [Link]
[87] [Link]
[88] [Link]
[89] [Link]
[90] [Link]
[91] [Link]
[92] [Link]
[93] [Link]
[94] [Link]
[95] [Link]
[96] [Link]
[97] [Link]
[98] [Link]
[99] [Link]
[100] [Link]
[101] [Link]
[102] [Link]
[103] [Link]
[104] [Link]
[105] [Link]
[106] [Link]
[107] [Link]
[108] [Link]
[109] [Link]
[110] [Link]
[111] [Link]
[112] [Link]
[113] [Link]
[114] [Link]
[115] [Link]
[115] [Link]
[116] [Link]
[117] [Link]
[118] [Link]
[119] [Link]
[120] [Link]
[121] [Link]
[122] [Link]
[123] [Link]
[124] [Link]
[125] [Link]
[126] [Link]
[127] [Link]
[128] [Link]
[129] [Link]
[130] [Link]
[131] [Link]
[132] [Link]
[133] [Link]
[134] [Link]
[135] [Link]
[136] [Link]
[137] [Link]
[138] [Link]
[139] [Link]
[140] [Link]
[141] [Link]
[142] [Link]
[143] [Link]
[144] [Link]
[145] [Link]
[146] [Link]
[147] [Link]
[148] [Link]
[149] [Link]
[150] [Link]
[151] [Link]
[152] [Link]
[153] [Link]
[154] [Link]
[155] [Link]
[156] [Link]
[157] [Link]
[158] [Link]
[159] [Link]
[160] [Link]
[161] [Link]
[162] [Link]
[163] [Link]
[164] [Link]
[165] [Link]
[166] [Link]
[167] [Link]
[168] [Link]
[169] [Link]
[170] [Link]
[171] [Link]
[172] [Link]
[173] [Link]
[174] [Link]
[175] [Link]
[176] [Link]
[177] [Link]
[178] [Link]
[179] [Link]
[180] [Link]
[181] [Link]
[182] [Link]
[183] [Link]
[184] [Link]
[185] [Link]
[186] [Link]
[187] [Link]
[188] [Link]
[189] [Link]
[190] [Link]
[191] [Link]
[192] [Link]
[193] [Link]
[194] [Link]
[195] [Link]
[196] [Link]
[197] [Link]
[198] [Link]
[199] [Link]
[200] [Link]
[201] [Link]
[202] [Link]
[203] [Link]
[204] [Link]
[205] [Link]
[206] [Link]
[207] [Link]
[207] [Link]
[208] [Link]
[209] [Link]
[210] [Link]
[211] [Link]
[212] [Link]
[213] [Link]
[214] [Link]
[215] [Link]
[216] [Link]
[217] [Link]
[218] [Link]
[219] [Link]
[220] [Link]
[221] [Link]
[222] [Link]
[223] [Link]
[224] [Link]
[225] [Link]
[226] [Link]
[227] [Link]
[228] [Link]
[229] [Link]
[230] [Link]
[231] [Link]
[232] [Link]
[233] [Link]
[234] [Link]
[235] [Link]
[236] [Link]
[237] [Link]
[238] [Link]
[239] [Link]
[240] [Link]
[241] [Link]
[242] [Link]
[243] [Link]
[244] [Link]
[245] [Link]
[246] [Link]
[247] [Link]
[248] [Link]
[249] [Link]
[250] [Link]
[251] [Link]
[252] [Link]
[253] [Link]
[254] [Link]
[255] [Link]
[256] [Link]
[257] [Link]
[258] [Link]
[259] [Link]
[260] [Link]
[261] [Link]
[262] [Link]
[263] [Link]
[264] [Link]
[265] [Link]
[266] [Link]
[267] [Link]
[268] [Link]
[269] [Link]
[270] [Link]
[271] [Link]
[272] [Link]
[273] [Link]
[274] [Link]
[275] [Link]
[276] [Link]
[277] [Link]
[278] [Link]
[279] [Link]
[280] [Link]
[281] [Link]
[282] [Link]
[283] [Link]
[284] [Link]
[285] [Link]
[286] [Link]
[287] [Link]
[288] [Link]
[289] [Link]
[290] [Link]
[291] [Link]
[292] [Link]
[293] [Link]
[294] [Link]
[295] [Link]
[296] [Link]
[297] [Link]
[298] [Link]
[299] [Link]
[299] [Link]
[300] [Link]
[301] [Link]
[302] [Link]
[303] [Link]
[304] [Link]
[305] [Link]
[306] [Link]