Javascript API

Using SPEL formulas has some limitations, that is why it can be helpful to use Javascript scripts. Alfresco can run those scripts through the rules system and beCPG can run them through project task formulation or entity formulation. Depending on the rule context, multiple root objects are available during the script execution. Warning creating javascript rules may impact the performances and rule proliferation, that is why beCPG provides common built-in helper methods from a single script.



You can check what are the root objects you have access to when implementing a script rule:

Formulation script

Variable Description
currentUser Current user login
entity Formulated entity (ProductData or ProjectData for example)

Task script

Variable Description
currentUser Current user login
task The TaskListDataItem object which is the current deliverable task
project The ProjectData object
shareUrl The application URL

Entry point

In order to limit the number of rules, BeCPG suggests to centralize the entity rules in the classify-entity.js script. This script also defines classifying rules and can be modified.


beCPG provides multiple helper methods to use.

To include them, you need to add the following line at the begining of your sript:

Constants Description
Methods Description
isEmpty(value) alias isNullOrEmpty(value) returns true if value is empty or null
orEmpty(value) returns value or empty if null;
propValue(node, propName) alias getProp(node, propName) returns node property value or empty
mlPropValue(node, propName, locale) alias getMLProp(node, propName, locale) returns node multilingual property value or empty for locale
mlPropConstraint(propValue, propName, locale) alias getMLConstraint(propValue, propName, locale) display value or empty for multilingual constraint value
assocValue(node, assocName) returns assoc nodeRef array
assocValues(node, assocName) assoc nodeRef arrays
assocPropValues(node, assocName, propName) alias getAssoc(product, assocName, propName?) returns association property array of values
assocPropValue(node, assocName, propName) returns association property value
assocAssocValues(node, assocName, assocAssocName) returns association association nodeRef array
assocAssocValue(node, assocName, assocAssocName) returns association association nodeRef
copyAssocPropValue(node, assocName, propName, nodePropName) Copy association property value to node property
copyAssocAssocValue(node, assocName, assocAssocName, nodeAssocName) Copy association association value to node association
updateAssoc(node, assocName, values) param values can be nodeRef, nodeRef array, scriptNode, scriptNode array
setValue(node, propName, value) Set property value checking if property changed returns if property has changed
setExtraValue(entity, propName, value) Set property value on repositoryEntity
updateMLText(node, propQName, locale, value) Update multilingual value
i18n(key, params?) returns i18n message for current locale
cleanName(value) alias removeForbiddenChar(value) returns valid cm:name value
concatName(name, value, separator?) param separator default is " " returns concatenated value of name + separator + value
classifyByHierarchy(productNode, folderNode, propHierarchy?) classify node by hierarchy
classifyByPropAndHierarchy(productNode, folderNode, propHierarchy?, propPathName?, locale?) classify node by prop and hierarchy
isInSite(productNode, siteId) returns true if node is in siteId
isInUserFolder(productNode) returns true if node is in user folder
getDocumentLibraryNodeRef(siteId) returns document library folder for site
createBranch(node, dest, autoMerge?) Create new branch of entity
mergeBranch( node, branchToNode, description, type) branchToNode can be null if autoMerge
moveAndRename(node,dest) Move node and rename if same name exists in destination
generateEAN13Code(prefix) returns generate EAN13 code with autonum corresponding to prefix
setPermissionAsSystem(node, permission, authority) Set permissions as system, node can be node or nodeRef
allowWrite(node, authority) Set write permissions as system bypassing rights
allowRead(node, authority) Set read permissions as system bypassing rights
deleteGroupPermission(node, group) Remove specific group permissions
clearPermissions(node, inherit) Remove permissions as system set on node, node can be node or nodeRef
copyList( sourceNode, destNode , listQname) Copy one list from sourceNode to destNode
listExist( node, listQname) returns true if list exists and non empty
listItems( node, listQname) returns list items
toISO8601(dateObject, options) convert date toISO8601
submitForm(entity, formDataJson) applies the given formulary to the entity
getEntityListFromNode(product, listName) returns the entity list node for the given list name
isOnCreateEntity(node) returns true if the node is on creation
isOnMergeEntity(node) returns true if the node is on merge
isOnMergeMinorVersion(node) returns true if the node is on merge with minor revision
isOnMergeMajorVersion(node) returns true if the node is on merge with major revision
isOnCopyEntity(node) returns true if the node is a new copy
isOnFormulateEntity(node) returns true if the node is formulated
isOnBranchEntity(node) returns true if the node is a new branch

Example :

 var geo = new Array();

updateAssoc(product, "bcpg:productGeoOrigin", geo)

Digital signature helpers

beCPG provides an add-on implementing a signature service for which multiple script methods were implemented.

You can check for more details.

Methods Description
bSign.prepareForSignature(document, recipients, params) Creates a working copy of a PDF and adds signature fields to it
document : document node you want to prepare for signature
recipients : recipients for the signature
params (optional) : list of parameters defining the position, the size and the key word used for the signature fields (check the document for more details)
bSign.getSignatureView(document, userName, task) Returns a URL to visually sign the prepared PDF
bSign.signDocument(document) Digitally signs the PDF document (which was prepared and visually signed before)

results matching ""

    No results matching ""