-
Notifications
You must be signed in to change notification settings - Fork 683
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
SapphicFire
merged 2 commits into
ServiceNowDevProgram:main
from
Soumyadeep10:Soumyadeep-6-businessRule-FetchingReferencefieldvaluefromhigher-levelparents
Oct 31, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...lue from higher-level parents/Fetching reference field value from higher-level parents.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
})(current, previous); |
12 changes: 12 additions & 0 deletions
12
Business Rules/Fetching reference field value from higher-level parents/readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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')
andsetValue('field',value)
as well as thegetValue()
method on GlideElements when dot-walking)There was a problem hiding this comment.
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