Sample Scripts
This section contains samples of work manager scripting and process manager scripting.
Example of Work Manager Scripting:
The JavaScript below is defined on the 'Schedule' Script, meaning that when the work item is scheduled, this script executes. The script is using the WorkManagerFactory.getWorkitem().getWorkItemOffers() method to return the list of resources to which the work item is offered.
WorkManagerFactory methods are defined in Process Manager and Work Manager Scripting.
var theOfferSet = bpm.workManager.getWorkItem().getWorkItemOffers(); var i = 0; data.DFOfferSet.length(0); while (i<theOfferSet.length()){ //loop through resources in offer set var resourcesFromOfferSet = theOfferSet.get(i).getName(); data.DFOfferSet.push(resourcesFromOfferSet); //add resource to OfferSet array field i++; }
Where 'DFOfferSet' is a data field defined in the process and added as an interface to the user task.
The WorkManagerFactory.getOrganizationModel method can be used to navigate around the organization model to identify a particular organizational entity, or aresource mapped to such an entity. For example:
var useResource = bpm.workManager.getOrganizationModel().getAssociatedResources(data.EasyAs.ClaimsDept.Manager)
Resources can be located using RQL queries, using the bpm.workManager.getOrganizationModel().getResourcesByQuery method.
Examples of Process Manager Scripting:
The JavaScript below is defined on the 'Initiate' Script meaning that when this user activity in initiated, this script will execute. The script is using the Process.getActivityLoopIndex() method to return the loop index for a multiple instance user task.
var myActivityLoopIndex = bpm.process.getActivityLoopIndex(); if (myActivityLoopIndex != null) { data.UTActivityLoopIndex = myActivityLoopIndex; }
Where 'UTActivityLoopIndex' is a data field defined in the process and added as an interface to the user task.
The following example shows extracts from a Process Manager script being used to get information about the organization model:
var orgModel = bpm.process.getOrgModel(); var unit1 = orgModel.ouByGuid("_xI4ikMpPEd64gM7QE8RwxA"); var position1 = orgModel.positionByName("clerk");