How to populate value in a related list based on the value of another related list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 06:01 AM
I have 2 Related list configured on User form ; 1) Roles ( 'Roles' table) 2) Ranks ('Ranks' table) .
I have a m2m table 'RolRankRelation' showing the relation between 'Roles' and 'Ranks' table.
The requirement is : Whenever the user selects a value in 'Roles' related list , the corresponding value based on the m2m table RolEntRelation table should reflect in Ranks related list and vice versa.
for eg: 'Data' in Roles tables is related to 'High' in 'Rank' table (got this from the 'RolRankRelation' table)
then in the User form ; when the user selects 'Data' in Roles related list then 'High' should appear in 'Rank' related list OR vice versa.
How can I achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2023 07:01 AM
Hi @KannanThambi ,
I trust you are doing great.
Here's an example of how you can implement this solution:
Create a new Business Rule on the 'Roles' table:
- Navigate to "System Definition" > "Business Rules" and click on "New".
- Give the Business Rule a name, such as "UpdateRanksRelatedList".
- Set the Table to "Roles".
- Set the When to "before" and the Insert, Update, and Delete checkboxes to trigger the Business Rule on those actions.
- In the Advanced section, set the Client checkbox to "true" to run the Business Rule on the client side.
- Click on "Submit" to create the Business Rule.
Write the client-side script in the Business Rule:
- In the "Advanced" section of the Business Rule, click on "Client Script" to open the client-side script editor.
- Write the following code:
(function () {
// Get the selected value from the 'Roles' related list
var selectedRole = g_form.getValue('roles'); // Replace 'roles' with the actual field name
// Query the 'RolRankRelation' table to get the corresponding rank
var rolRankRelation = new GlideRecord('RolRankRelation');
rolRankRelation.addQuery('roles', selectedRole); // Replace 'roles' with the actual field name
rolRankRelation.query();
if (rolRankRelation.next()) {
// Set the value of the 'Rank' related list to the corresponding rank
g_form.setValue('rank', rolRankRelation.ranks.toString()); // Replace 'rank' with the actual field name
} else {
// Clear the value of the 'Rank' related list if no corresponding rank is found
g_form.setValue('rank', '');
}
})();
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2023 02:51 AM - edited ‎06-15-2023 02:51 AM
Hi Amit, thank you
but a doubt , shouldn't the Business rule be created on User table?