Skip to content

Business rule for fetching reference field value from higher-level parents #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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
// I would be referring to "reference field name we want to populate" as "r1"
// I would be referring to "reference field containing parent record" as "parent"


(function executeRule(current, previous /*null when async*/ ) {
if (current.r1 == "" && !JSUtil.nil(current.parent.r1)) // Populate 'use-case reference field' from parent's value for the reference field'
current.r1 = current.parent.r1;
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'
current.r1 = current.parent.parent.r1;
Comment on lines +7 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In future, use the getter and setter methods (getValue('field') and setValue('field',value) as well as the getValue() method on GlideElements when dot-walking)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gs.nil() does the same functionality as JSUtil


})(current, previous);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This is a "**before insert/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

In the code, we are referring to "reference field name we want to populate" as "_r1_"
In the code, we are referring to "reference field containing parent record" as "_parent_"

The "**JSUtil.nil**" is being used to check for empty/null value for the field.


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
Loading