From 1cf44bb78ffcc2c20b815688815c4206ea5d4175 Mon Sep 17 00:00:00 2001
From: Simon Leipold <s.leipold@adito.de>
Date: Thu, 5 Mar 2020 14:56:59 +0100
Subject: [PATCH] [Projekt: Entwicklung - Neon][TicketNr.: 1053536][Neuanlage
 von Rolle mit Kindrollen wirft Fehler]

---
 .../RoleChildren_entity.aod                   |  4 ++++
 .../recordcontainers/jdito/contentProcess.js  | 17 ++++++++++++-----
 .../recordcontainers/jdito/onInsert.js        | 19 ++++++++++++-------
 .../recordcontainers/jdito/onUpdate.js        |  5 +++--
 entity/Role_entity/Role_entity.aod            |  4 ++++
 .../children/roletype_param/valueProcess.js   |  4 ++++
 6 files changed, 39 insertions(+), 14 deletions(-)
 create mode 100644 entity/Role_entity/entityfields/rolechildrens/children/roletype_param/valueProcess.js

diff --git a/entity/RoleChildren_entity/RoleChildren_entity.aod b/entity/RoleChildren_entity/RoleChildren_entity.aod
index 78d1c42ce37..d7607769b00 100644
--- a/entity/RoleChildren_entity/RoleChildren_entity.aod
+++ b/entity/RoleChildren_entity/RoleChildren_entity.aod
@@ -45,6 +45,10 @@
         <fieldName>Roles</fieldName>
       </dependency>
     </entityConsumer>
+    <entityParameter>
+      <name>RoleType_param</name>
+      <expose v="true" />
+    </entityParameter>
   </entityFields>
   <recordContainers>
     <jDitoRecordContainer>
diff --git a/entity/RoleChildren_entity/recordcontainers/jdito/contentProcess.js b/entity/RoleChildren_entity/recordcontainers/jdito/contentProcess.js
index 9732fa101c6..a76ad51dc5d 100644
--- a/entity/RoleChildren_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/RoleChildren_entity/recordcontainers/jdito/contentProcess.js
@@ -1,3 +1,4 @@
+import("system.neon");
 import("Sql_lib");
 import("system.db");
 import("system.vars");
@@ -6,15 +7,21 @@ import("system.util");
 
 var alias = SqlUtils.getSystemAlias();
 var selectedRoleName = vars.exists("$param.RoleId_param") && vars.get("$param.RoleId_param");
+var selectedRoleType = vars.exists("$param.RoleType_param") && vars.get("$param.RoleType_param");
 var children = [];
 
+if (selectedRoleType == "" && selectedRoleName != "") {
+    selectedRoleType = "CUSTOM";
+    selectedRoleName = selectedRoleType + "_" + selectedRoleName;
+}
+
 // roles can only be assigned to CUSTOM roles -> selected role has to be a viable CUSTOM role
-if (selectedRoleName && selectedRoleName.indexOf("CUSTOM_") != -1) {
+if (selectedRoleName && selectedRoleType == "CUSTOM") {
     var childRoles = newSelect("ID, CHILD_ROLE", alias)
-    .from("ASYS_ROLES_CHILDREN")
-    .where("ASYS_ROLES_CHILDREN.PARENT_ROLE", selectedRoleName)
-    .table();
-
+        .from("ASYS_ROLES_CHILDREN")
+        .where("ASYS_ROLES_CHILDREN.PARENT_ROLE", selectedRoleName)
+        .table();
+    
     for each (let childRole in childRoles) {
         children.push([childRole[0], childRole[1], selectedRoleName]);
     }
diff --git a/entity/RoleChildren_entity/recordcontainers/jdito/onInsert.js b/entity/RoleChildren_entity/recordcontainers/jdito/onInsert.js
index 60f0bfa2155..6dd14e23f2b 100644
--- a/entity/RoleChildren_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/RoleChildren_entity/recordcontainers/jdito/onInsert.js
@@ -1,14 +1,19 @@
+import("system.neon");
 import("system.util");
 import("system.db");
 import("Sql_lib");
 import("system.result");
 import("system.vars");
 
-var parentRoleName = vars.exists("$param.RoleId_param") && vars.get("$param.RoleId_param")
+var selectedRoleName = vars.exists("$param.RoleId_param") && vars.get("$param.RoleId_param")
+var selectedRoleType = vars.exists("$param.RoleType_param") && vars.get("$param.RoleType_param");
 
-if (parentRoleName && parentRoleName.indexOf("CUSTOM_") != -1) {
-    var alias = SqlUtils.getSystemAlias();
-    var childRole = vars.get("$local.rowdata")["CHILD_ROLE.value"];
-    var uid = vars.get("$field.UID") 
-    db.insertData("ASYS_ROLES_CHILDREN", ["CHILD_ROLE", "PARENT_ROLE", "ID"], null, [childRole, parentRoleName, uid], alias);
-}
\ No newline at end of file
+if (selectedRoleType == "" && selectedRoleName != "") {
+    selectedRoleType = "CUSTOM";
+    selectedRoleName = selectedRoleType + "_" + selectedRoleName;
+}
+
+var alias = SqlUtils.getSystemAlias();
+var childRole = vars.get("$local.rowdata")["CHILD_ROLE.value"];
+var uid = vars.get("$field.UID") 
+db.insertData("ASYS_ROLES_CHILDREN", ["CHILD_ROLE", "PARENT_ROLE", "ID"], null, [childRole, selectedRoleName, uid], alias);
\ No newline at end of file
diff --git a/entity/RoleChildren_entity/recordcontainers/jdito/onUpdate.js b/entity/RoleChildren_entity/recordcontainers/jdito/onUpdate.js
index 3d8ff706334..ef5e24b81d4 100644
--- a/entity/RoleChildren_entity/recordcontainers/jdito/onUpdate.js
+++ b/entity/RoleChildren_entity/recordcontainers/jdito/onUpdate.js
@@ -4,9 +4,10 @@ import("Sql_lib");
 import("system.result");
 import("system.vars");
 
-var parentRoleName = vars.exists("$param.RoleId_param") && vars.get("$param.RoleId_param")
+var selectedRoleName = vars.exists("$param.RoleId_param") && vars.get("$param.RoleId_param");
+var selectedRoleType = vars.exists("$param.RoleType_param") && vars.get("$param.RoleType_param");
 
-if (parentRoleName && parentRoleName.indexOf("CUSTOM_") != -1) {
+if (selectedRoleName && selectedRoleType == "CUSTOM") {
     var alias = SqlUtils.getSystemAlias();
     var childRole = vars.get("$local.rowdata")["CHILD_ROLE.value"];
 
diff --git a/entity/Role_entity/Role_entity.aod b/entity/Role_entity/Role_entity.aod
index 8e6196406f4..57a20f63477 100644
--- a/entity/Role_entity/Role_entity.aod
+++ b/entity/Role_entity/Role_entity.aod
@@ -143,6 +143,10 @@
           <name>RoleId_param</name>
           <valueProcess>%aditoprj%/entity/Role_entity/entityfields/rolechildrens/children/roleid_param/valueProcess.js</valueProcess>
         </entityParameter>
+        <entityParameter>
+          <name>RoleType_param</name>
+          <valueProcess>%aditoprj%/entity/Role_entity/entityfields/rolechildrens/children/roletype_param/valueProcess.js</valueProcess>
+        </entityParameter>
       </children>
     </entityConsumer>
     <entityActionField>
diff --git a/entity/Role_entity/entityfields/rolechildrens/children/roletype_param/valueProcess.js b/entity/Role_entity/entityfields/rolechildrens/children/roletype_param/valueProcess.js
new file mode 100644
index 00000000000..6d8c8166db1
--- /dev/null
+++ b/entity/Role_entity/entityfields/rolechildrens/children/roletype_param/valueProcess.js
@@ -0,0 +1,4 @@
+import("system.result");
+import("system.vars");
+
+result.string(vars.get("$field.ROLETYPE"));
\ No newline at end of file
-- 
GitLab