Creating a Role Report
This example shows how to collect all roles in a process and their assigned users.
1. Create a Report with a Stages Data Source and a Data Set
2. Create the following Data Set result columns:
Name | Type |
---|---|
Username | String |
Fullname | String |
LicenseType | String |
Name | String |
EmailAddress | String |
Indented | String |
3. Copy the Data Set script from the example into your Data Set.
Example
function getChilds(element,mylevel) { var children_level = mylevel + 1; var myelements = element.getEntities("hierarchy::hierarchic@LOCAL,targetrole=children"); for each (myelement in myelements) { getUsers(myelement,mylevel); gethilds(myelement,children_level); } } function getIndex(myelement) { do { var parent = myelement.getEntities("hierarchy::HIERARCHIC@LOCAL,targetrole=parent"); if (parent[0].getProperty("IndexMode")==1) { return (parent[0]); } myelement = parent[0]; } while (parent[0].getProperty("IndexMode")!=1); return (null); } function addSpaces (n) { var string = ""; for (var i=0; i<n; i++) { string = string+" "; } return string; } function getUsers(myelement, mylevel) { var myUsers = myelement.getEntities("containsUser@SYSTEM"); for each (myUser in myUsers) { dataset.setColumnValue("Username",myUser.getProperty("Username")); dataset.setColumnValue("Fullname",myUser.getProperty("Fullname")); dataset.setColumnValue("LicenseType",myUser.getProperty("LicenseType")); dataset.setColumnValue("EmailAddress",myUser.getProperty("EmailAddress")); saveColumn(myelement,mylevel) } if (myUsers.length==0) saveColumn(myelement,mylevel); } function saveColumn(element,mylevel) { dataset.setColumnValue("Name",element.getProperty("DisplayName")); dataset.setColumnValue("indented",addSpaces(mylevel) +element.getProperty("DisplayName")); dataset.storeResultRow(); } var currentProject = pkit.getCurrentProject(); var process = currentProject.getEntities("containsProcess@SYSTEM")[0]; var assocs = process.getPkitClass().getAssociations(); for each (assoc in assocs) { if (assoc.getName().match(/Role/)) { var elements = process.getEntities(assoc.getName()); if (elements.length> 0) { act_index = getIndex(elements[0]); getChilds(act_index,0) } } }