Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Last revisionBoth sides next revision
72:custom_report_tipsandtricks_switch [2019/02/07 13:50] – created ext-bkkr72:custom_report_tipsandtricks_switch [2019/03/08 19:07] ext-bkkr
Line 1: Line 1:
 ====== Switch Context to Viewing User ====== ====== Switch Context to Viewing User ======
  
 +Each dataset script is executed by default with the datasource user. That means that the report is fixed to one user regardless of the user who is executing the report in Stages. With the asCurrentUser.run() method, it is possible to switch the context to the viewing user (the user who is executing the report in Stages).
 +
 +<code>
 +function debug(str) {
 + dataset.setColumnValue("debug",str);
 + dataset.storeResultRow();
 +}
 +function projectparent(project) {
 + var myprojects =
 + project.getEntities("hierarchy::hierarchic@LOCAL,targetrole=parent");
 + var Path = new Array();
 + if (myprojects.length == 0) {
 + Path.unshift(project.getProperty("Name"));
 + return Path;
 + }
 + var Name = myprojects[0].getProperty("Name");
 + Path.unshift(project.getProperty("Name"));
 + while (!Name.match(/INDEX/)) {
 + Path.unshift(Name);
 + project = myprojects[0];
 + myprojects =
 + project.getEntities("hierarchy::hierarchic@LOCAL,targetrole=parent");
 + if (myprojects.length ==0)
 + break;
 + Name = myprojects[0].getProperty("Name");
 + }
 + return Path;
 +}
 +asCurrentUser.run( function () {
 + var roles = currentUser.getEntities("containsUser@SYSTEM");
 + for each ( role in roles) {
 + dataset.setColumnValue("user",currentUser.getProperty("Fullname"));
 + dataset.setColumnValue("role",role.getProperty("DisplayName"));
 + var project = role.getEntities("containsRole@SYSTEM")
 +[0].getEntities("containsProcess@SYSTEM")[0];
 + dataset.setColumnValue("project",projectparent(project).join(">"));
 + dataset.storeResultRow();
 + }
 + if (roles.length == 0) {
 + dataset.setColumnValue("user",currentUser.getProperty("Fullname"));
 + dataset.setColumnValue("role","none");
 + dataset.storeResultRow();
 + }
 +
 + }
 +)
 +</code>