Skip to content

Commit 77bce1e

Browse files
authored
Business rule for fetching reference field value from higher-level parents (#1585)
* Fetching reference field value from higher-level parents.js In this before insert or update Business Rule, we are fetching a reference field value from higher-level parents in hierarchy when there is a field containing the parent record in the children and our use-case reference field is present in all the tables in hierarchy. * readme.md In this before insert or update Business Rule, we are fetching a reference field value from higher-level parents in hierarchy when there is a field containing the parent record in the children and our use-case reference field is present in all the tables in hierarchy.
1 parent 4523c2b commit 77bce1e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// In this before insert or update Business Rule, we are fetching a reference field value from higher-level parents in hierarchy when there is a field containing the parent record in the children and our use-case reference field is present in all the tables in hierarchy
2+
// I would be referring to "reference field name we want to populate" as "r1"
3+
// I would be referring to "reference field containing parent record" as "parent"
4+
5+
6+
(function executeRule(current, previous /*null when async*/ ) {
7+
if (current.r1 == "" && !JSUtil.nil(current.parent.r1)) // Populate 'use-case reference field' from parent's value for the reference field'
8+
current.r1 = current.parent.r1;
9+
else if (current.< reference field name we want to populate > == "" && !JSUtil.nil(current.parent.parent.r1)) // Populate 'use-case reference field' from 'parent of parent'
10+
current.r1 = current.parent.parent.r1;
11+
12+
})(current, previous);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This is a "**before insert/update**" Business Rule
2+
We are fetching a reference field value from higher-level parents in hierarchy
3+
when there is a field containing the parent record in the children and
4+
our use-case reference field is present in all the tables in hierarchy
5+
6+
In the code, we are referring to "reference field name we want to populate" as "_r1_"
7+
In the code, we are referring to "reference field containing parent record" as "_parent_"
8+
9+
The "**JSUtil.nil**" is being used to check for empty/null value for the field.
10+
11+
12+
Through the code we are checking the empty value of the use-case reference field and dot walking to parents and fetching the value from them if it exists

0 commit comments

Comments
 (0)