diff --git a/entity/RoleChildren_entity/entityfields/child_role/dropDownProcess.js b/entity/RoleChildren_entity/entityfields/child_role/dropDownProcess.js index 34affa61dc9eb6de36676e40f39582359f29b54c..8867a68b1cb4c9e3d8b2d4fdb5b61936c46cdf5b 100644 --- a/entity/RoleChildren_entity/entityfields/child_role/dropDownProcess.js +++ b/entity/RoleChildren_entity/entityfields/child_role/dropDownProcess.js @@ -7,15 +7,32 @@ var newChildRoles = []; var alias = SqlUtils.getSystemAlias(); var parentRole = vars.get("$param.RoleId_param"); var allCustomAndProjectRoles = tools.getAllRoles(["CUSTOM", "PROJECT"], true); + var childRoles = newSelect("CHILD_ROLE", alias) .from("ASYS_ROLES_CHILDREN") .where("ASYS_ROLES_CHILDREN.PARENT_ROLE", parentRole) .table(); +var parentIsAlreadyChildOf = newSelect("PARENT_ROLE", alias) +.from("ASYS_ROLES_CHILDREN") +.where("ASYS_ROLES_CHILDREN.CHILD_ROLE", parentRole) +.table(); + for each (let role in allCustomAndProjectRoles) { - if (role[3] != parentRole) { // dont show same role as parent in dropdown + // dont show current role as possible child in dropdown + if (role[3] != parentRole) { newChildRoles.push([role[3], role[3]]); } } +// check for cyclces in hierarchy, A can't be child of B while it is already parent of B +for each (let role in parentIsAlreadyChildOf) { + newChildRoles = newChildRoles.filter(function(childRole) { + if (role == childRole[0]) { + return false; + } + return true; + }); +} + result.object(newChildRoles.sort()); \ No newline at end of file