Contents
Objective
The purpose of this guide is to provide instructions on how to build a script with the purpose of solving a assignee for a workflow process task and/or process manager.
Requirements
- Knowledge of JavaScript language;
- Knowledge on the construction of Workflow Fluig process flows;
- Knowledge on using Fluig Datasets;
- Understanding of Web, Webservice, SOAP e XML services;
- Familiarity with the development tool, TOTVS Developer Studio or Eclipse;
- Installation of Fluig Studio.
Building a Custom Mechanism
In some situations, a more complex and specific logic is required regarding the definition of who will be responsible for the execution of the activity in the workflow process request. That is the purpose of the "Custom Attribution Mechanism".
To start building this mechanism, one should, from an existing project, click on the folder mechanisms and access the menu File > New > Other... (accessible through the shortcutCTRL+N, or by clicking the folder with the right mouse button, then following the drop-down menu), expand the Fluig group (folder), select Custom Fluig Mechanism and click on Next. In the following screen, enter the Code (mandatory and cannot be changed at a later time) in the respective field and its Description (optional), and, lastly, click Finish.
Therefore, this basic function will be created, and must be implemented:
function resolve(process,colleague){ var userList = null; return userList; }
The function above does not return any user. Its execution will not enable the selection of a user, and therefore the function must be complemented.
The function should return an ArrayList with the registration of users. The registration is not necessarily the same as the user login. The registration corresponds to existing value in the field with the same name as the registration for this user and the column colleaguePK.colleagueId, of the Dataset colleague.
Returning a User List
An example of return for a fixed user list is shown below:
function resolve(process,colleague){ var userList = new java.util.ArrayList(); userList.add('matricula_1'); userList.add('matricula_2'); userList.add('matricula_3'); return userList; }
Using Datasets
It is possible to query a Platform Dataset (internal, forms or customized), in order to draw up the final result of users that may be listed for selection of the execution of the next activity. This procedure must be performed according to the example below:
function resolve(process,colleague){ var userList = new java.util.ArrayList(); //-- QUERY TO A DATASET, OF FLUIG USERS GROUP var dtsGroup = DatasetFactory.getDataset('group',null,null,null); for(var g = 0; g < dtsGroup.values.length; g++){ userList.add( 'Pool:Group:'+dtsGroup.getValue(g.toString(),"groupPK.groupId") ); } //-- QUERY TO A DATASET, OF FLUIG USERS ROLE var dtsRole = DatasetFactory.getDataset('workflowRole',null,null,null); for each(papel in dtsRole.values){ userList.add( 'Pool:Role:'+papel["workflowRolePK.roleId"] ); } return userList; }
In the example above, in order for the Group(s) to be listed, it is necessary to include the prefix "Pool: Group:" concatenated to the code for this Group. With this, when the group is selected, the activity is attributed to the Group and someone from the group should assume it. The same is true for the Workflow Role(s), however the prefix will be "Pool:Role:", followed by the Role code.
Using Services / Webservices
The construction of a mechanism also enables the use of a Fluig Integration Service, which may consume a SOAP or Progress webservice to retrieve the assignees, according to a business rule provided by the ERP, for example. This method may follow the model below:
function resolve(process,colleague){ var userList = new java.util.ArrayList(); //-- CALL TO A FLUIG INTEGRATION SERVICE, WITH A SPECIFIED WEBSERVICE var biblioteca = ServiceManager.getService('ECMColleagueService').getBean(); var endpoint = biblioteca.instantiate('com.totvs.technology.ecm.foundation.ws.ECMColleagueServiceServiceLocator'); var webservice = endpoint.getColleagueServicePort(); var usuariosDtoArray = webservice.getSummaryColleagues(1); for each(usuario in usuariosDtoArray.getItem()){ userList.add( usuario.getColleagueId().toString() ); } return userList; }
Where the "process" and "colleague" parameters refer, respectively, to the objects WorkflowProcess process and Colleague colleague.
WorkflowProcess | |
---|---|
Parameter | Type |
companyId | long |
processInstanceId | int |
processId | String |
version | Integer |
requesterId | String |
active | Boolean |
attachmentSeqId | Integer |
sourceProcess | Integer |
sourceThreadSequence | Integer |
uuid | String |
Colleague | |
---|---|
Parameter | Type |
colleaguePK
| ColleaguePK |
userTenantId | long |
colleagueName | String |
String | |
login | String |
passwd | String |
active | Boolean |
adminUser | Boolean |
groupId | String |
The example above used the webservice ECMColleagueService, from the very platform, and the Service was created with API Axis, standard in TOTVS ECM 3.0.