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

Conversation

Soumyadeep10
Copy link
Contributor

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

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

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.
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.
@SapphicFire SapphicFire self-assigned this Oct 31, 2024
Copy link
Contributor

@SapphicFire SapphicFire left a comment

Choose a reason for hiding this comment

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

Accepting and have given some advice to consider going forward

Comment on lines +7 to +10
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;
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

@SapphicFire SapphicFire merged commit 77bce1e into ServiceNowDevProgram:main Oct 31, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants