How to populate value in a related list based on the value of another related list

KannanThambi
Tera Contributor

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?

2 REPLIES 2

Amit Gujarathi
Giga Sage
Giga Sage

Hi @KannanThambi ,
I trust you are doing great.

Here's an example of how you can implement this solution:

  1. 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.
  2. 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



Hi Amit, thank you
but a doubt , shouldn't the Business rule be created on User table?