From ed3901a7d1e32e4ab860586574d4266bcb3c54f0 Mon Sep 17 00:00:00 2001
From: "m.escher" <m.escher@adito.de>
Date: Wed, 13 Feb 2019 07:49:04 +0100
Subject: [PATCH] #1034158 change AttributeRelation Entity: - reset Values on
 AttributeId valueChange - boolean_value accepts null

---
 .../AttributeRelation_entity.aod                      |  2 +-
 .../entityfields/ab_attribute_id/onValueChange.js     | 11 +++++++++++
 .../entityfields/bool_value/valueProcess.js           |  5 +++--
 .../entityfields/object_rowid/valueProcess.js         |  2 +-
 .../struct/AditoBasic/create_ab_attributerelation.xml |  4 +---
 5 files changed, 17 insertions(+), 7 deletions(-)
 create mode 100644 entity/AttributeRelation_entity/entityfields/ab_attribute_id/onValueChange.js

diff --git a/entity/AttributeRelation_entity/AttributeRelation_entity.aod b/entity/AttributeRelation_entity/AttributeRelation_entity.aod
index 80addbafcc8..d15eed456ad 100644
--- a/entity/AttributeRelation_entity/AttributeRelation_entity.aod
+++ b/entity/AttributeRelation_entity/AttributeRelation_entity.aod
@@ -18,7 +18,7 @@
       <title>Attribute</title>
       <mandatory v="true" />
       <possibleItemsProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/possibleItemsProcess.js</possibleItemsProcess>
-      <stateProcess>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/stateProcess.js</stateProcess>
+      <onValueChange>%aditoprj%/entity/AttributeRelation_entity/entityfields/ab_attribute_id/onValueChange.js</onValueChange>
     </entityField>
     <entityField>
       <name>OBJECT_ROWID</name>
diff --git a/entity/AttributeRelation_entity/entityfields/ab_attribute_id/onValueChange.js b/entity/AttributeRelation_entity/entityfields/ab_attribute_id/onValueChange.js
new file mode 100644
index 00000000000..e641c892888
--- /dev/null
+++ b/entity/AttributeRelation_entity/entityfields/ab_attribute_id/onValueChange.js
@@ -0,0 +1,11 @@
+import("system.vars");
+import("system.neon");
+
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT || 
+    vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) {
+    neon.setFieldValue("$field.BOOL_VALUE", null);
+    neon.setFieldValue("$field.CHAR_VALUE", null);
+    neon.setFieldValue("$field.DATE_VALUE", null);
+    neon.setFieldValue("$field.ID_VALUE", null);
+    neon.setFieldValue("$field.NUMBER_VALUE", null);
+}
\ No newline at end of file
diff --git a/entity/AttributeRelation_entity/entityfields/bool_value/valueProcess.js b/entity/AttributeRelation_entity/entityfields/bool_value/valueProcess.js
index 13b11be60e6..c5937313ed5 100644
--- a/entity/AttributeRelation_entity/entityfields/bool_value/valueProcess.js
+++ b/entity/AttributeRelation_entity/entityfields/bool_value/valueProcess.js
@@ -1,3 +1,4 @@
+import("system.vars");
 import("system.result");
-
-result.string("0")
\ No newline at end of file
+if(!vars.get("$field.BOOL_VALUE"))
+    result.string("0");
\ No newline at end of file
diff --git a/entity/AttributeRelation_entity/entityfields/object_rowid/valueProcess.js b/entity/AttributeRelation_entity/entityfields/object_rowid/valueProcess.js
index 83fdc179510..5f2f5a7b0d3 100644
--- a/entity/AttributeRelation_entity/entityfields/object_rowid/valueProcess.js
+++ b/entity/AttributeRelation_entity/entityfields/object_rowid/valueProcess.js
@@ -2,5 +2,5 @@ import("system.vars");
 import("system.result");
 import("system.neon");
 
-if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.exists("$param.objectRowId_param") && vars.get("$param.objectRowId_param") != null)
+if (vars.exists("$param.objectRowId_param") && vars.get("$param.objectRowId_param") != null)
     result.string(vars.get("$param.objectRowId_param"));
\ No newline at end of file
diff --git a/others/db_changes/data_alias/struct/AditoBasic/create_ab_attributerelation.xml b/others/db_changes/data_alias/struct/AditoBasic/create_ab_attributerelation.xml
index 260e47f10cc..6050c7975f3 100644
--- a/others/db_changes/data_alias/struct/AditoBasic/create_ab_attributerelation.xml
+++ b/others/db_changes/data_alias/struct/AditoBasic/create_ab_attributerelation.xml
@@ -18,9 +18,7 @@
             <column name="ID_VALUE" type="CHAR(36)"/>
             <column name="DATE_VALUE" type="DATETIME"/>
             <column name="NUMBER_VALUE" type="NUMERIC(14,2)"/>
-            <column name="BOOL_VALUE" type="TINYINT">
-                <constraints nullable="false"/>
-            </column>
+            <column name="BOOL_VALUE" type="TINYINT"/>
         </createTable>
     </changeSet>
 </databaseChangeLog>
\ No newline at end of file
-- 
GitLab