How to use the fields of the reference tablle in a BR

Shreshta_happy
Tera Contributor

I Have a BR that is on wo table , 

there is a field abc on the wo which is the reference field from tow table

when the tow state changes then the BR should execute. 

how to track the changes of the state of reference table

 

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

In this scenario, you need a Business Rule on the tow table that triggers when State changes.  The script would then have to do whatever to the wo record, not the other way around.

vennelasai
Tera Contributor

Hi @Shreshta_happy 

 

Here you have to create after update business rule,

table: tow

when to run: after and check update check box

condition: state changes to "your value"

then provide your login what needs to be happen on after business rule triggered.

 

Please mark it correct/helpful if this works for you.

 

Thanks,

Vennela 

 

 

Juhi Poddar
Kilo Patron

Hello @Shreshta_happy 

 

To execute a Business Rule (BR) on the Work Order (wo) table when the state of a referenced Task Order (tow) record changes, you can use the following approach:

Steps:

  1. Use a Business Rule on the tow table:

    • Since the state field change occurs on the tow table, create the Business Rule on this table, not on the wo table.
  2. Query for Related wo Records:

    • Use the abc field on the wo table (the reference to tow) to identify which wo records are affected.
  3. Update or Take Action on the wo:

    • Trigger your desired logic on the related wo records.

Create a Business Rule on the tow table:

Business Rule Details:

  • Table: tow
  • When to run: After (best for detecting field changes)
  • Condition: current.state.changes()
  • Example Script:

 

// Query the 'wo' table for related records where 'abc' points to the current 'tow'
var grWO = new GlideRecord('wo');
grWO.addQuery('abc', current.sys_id); // 'abc' is the reference field pointing to 'tow'
grWO.query();

while (grWO.next()) {
    // Add your logic here, e.g., update a field on the 'wo' table
    grWO.u_custom_field = 'State of TOW changed to ' + current.state; // Example action
    grWO.update(); // Save changes
}

// Optionally, log the change for debugging
gs.log('State changed for TOW: ' + current.sys_id + ', WO records updated.');
​

 

Hope this helps!

 

"If you found my answer helpful, please like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar