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.

Contexts

Rule

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

https://docs.alfresco.com/content-services/latest/develop/reference/repo-root-objects-ref/

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.

Helper

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
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 or empty if exactLocale = true else it will return the default locale
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 return the autonum value of the property's classname provided
incrementAndGetAutoNumCounter(autoNumClassName, propName) alias autoNumCounter(autoNumClassName, propName) increments and return the counter value of the property's classname provided (without prefix)
getAutoNumNodeRef(autoNumClassName, propName) alias autoNumNodeRef(autoNumClassName, propName) returns the NodeRef of the counter for the property's classname provided
setAutoNumValue(autoNumClassName, propName, counter) sets the value of the counter of the autonum value for the property's classname provided
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
addAspectToNode(node, aspectId) add an aspectId to a node if not used
removeAspectToNode(node, aspectId) remove an aspectId to a node if used

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 implementing a signature service for which multiple script methods were implemented.

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 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 ""