JavaScript API

SPEL formulas have some limitations, so JavaScript scripts can be helpful. Alfresco runs these scripts through the rules system, and beCPG runs them through project task formulation or entity formulation. Depending on the rule context, several root objects are available during script execution.

Warning: creating JavaScript rules may impact performance and lead to rule proliferation. That is why beCPG provides common built-in helper methods in a single script.

Contexts

Rule

To see which root objects you can access when implementing a script rule, check:

https://docs.alfresco.com/content-services/latest/

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

To limit the number of rules, beCPG recommends centralizing the entity rules in the classify-entity.js script. This script also defines classification rules, and you can modify it.

Helper

beCPG provides several helper methods.

To include them, add the following line at the beginning of your script:

<import resource="classpath:/beCPG/rules/helpers.js">
Constants Description
SIMULATION_SITE_ID
VALID_SITE_ID
ARCHIVED_SITE_ID
SUPPLIER_PORTAL_SITE_ID
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, exactLocale? false) alias getMLProp(node, propName, locale) returns the node's multilingual property value for the specified locale; if there is none, returns empty when exactLocale = true, otherwise the default locale value
mlPropConstraint(propValue, propName, locale) alias getMLConstraint(propValue, propName, locale) display value or empty for multilingual constraint value
incrementAndGetAutoNumValue(autoNumClassName, propName) alias autoNumValue(autoNumClassName, propName) increments and returns the autonum value for the provided class name and property
incrementAndGetAutoNumCounter(autoNumClassName, propName) alias autoNumCounter(autoNumClassName, propName) increments and returns the counter value for the provided class name and property (without prefix)
getAutoNumNodeRef(autoNumClassName, propName) alias autoNumNodeRef(autoNumClassName, propName) returns the NodeRef of the counter for the provided class name and property
setAutoNumValue(autoNumClassName, propName, counter) sets the autonum counter value for the provided class name and property
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) Sets the property value if it changed; returns whether the property 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 a generated EAN13 code with the autonum corresponding to the 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 form data 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
addAspectToNode(node, aspectId) add an aspectId to a node if not used
removeAspectToNode(node, aspectId) remove an aspectId from a node if used
sourceAssocValues(node, assocName, maxResults, offset, includeVersions) get the array of source associations, with maxResults (by default -1), offset (by default 0) and includeVersions (by default false)
hasEntitySourceAssocs(node, assocName, filter) returns true if the node is used in an assocName, considering a filter (JSON format)
entitySourceAssocs(node, assocName, filter) returns an array of nodeRefs if the node is used in an assocName, considering a filter (JSON format)

Example:

 var geo = new Array();
geo.push(search.findNode("workspace://SpacesStore/f61f7026-3457-4468-aa49-28136dce3443"));
geo.push(search.findNode("workspace://SpacesStore/3074da0c-81e8-4f31-923b-05937da09e0a"));
geo.push(search.findNode("workspace://SpacesStore/20a32eb1-3bfa-43df-ac4e-9c640d4de927"));

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

Digital signature helpers

beCPG provides an add-on that implements a signature service, with several script methods.

You can check https://github.com/becpg/becpg-artworks 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 keyword used for the signature fields (see the documentation 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 ""