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 this work item is scheduled this script will execute. 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 ’Work Manager Scripting’ in the TIBCO ActiveMatrix BPM Business Data Services guide.

var theOfferSet = WorkManagerFactory.getWorkItem().getWorkItemOffers();
var i = 0;
DFOfferSet.clear();
while (i<theOfferSet.size()){
//loop through resources in offer set
      var resourcesFromOfferSet = theOfferSet.get(i).getName();
      DFOfferSet.add(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 =
WorkManagerFactory.getOrganizationModel().getAssociatedResources(E
asyAs.ClaimsDept.Manager)
Resources can be located using RQL queries, using the getOrganizationModel().getResourcesByQuery method. See "Resource Query Language" in TIBCO Business Studio BPM Implementation Guide for more information.

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 = Process.getActivityLoopIndex();
if (myActivityLoopIndex != null)
{
      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 = Process.getOrgModel();
var unit1 = orgModel.ouByGuid("_xI4ikMpPEd64gM7QE8RwxA");
var position1 = orgModel.positionByName("clerk");