- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
1.I have two tables, u_actuant_times and u_actuant_times_details, both of which have the u_assigend_to field. 2.Among them, the associated fields of u_actuant_times_details and u_actuant_times are u_ ref Monday, u_ ref Tuesday... u_ ref Sunday.
3.Now I want to implement the following function: when I modify the value of the u_assigend_to field in u_actuant_times, I also modify the value of the u_assigend_to field in the u_actuant_times_details table.
How should the above functions be implemented?
The above figure shows the u_ actual times table
The red box shows the structure of the u_actuant_times_tail table
I want to change the value of 'Assigned to' in u_actual_times in real-time after modifying the 'assigned to' in u'actual_times_detail. How to achieve it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
Hi @shiz ,
Write After Business Rule in u_actuant_times table.
Update checkbox checked
Filter Condition: [u_assigned_to] [changes]
Script like:
(function executeRule(current, previous /*null when async*/) { // Get the sys_id of the current (parent) record var parentSysId = current.getUniqueValue(); // Get the new value of the u_assigned_to field var newAssignedTo = current.u_assigned_to.toString(); // Query the u_actuant_times_details table for associated records var detailGr = new GlideRecord('u_actuant_times_details'); // The details table has fields referencing the parent table (Monday, Tuesday, etc.) // We need to find records where any of these reference fields match the parent's sys_id. // Use an encoded query or multiple addQuery/addOrCondition statements detailGr.addQuery('u_ref_monday', parentSysId); detailGr.addOrCondition('u_ref_tuesday', parentSysId); detailGr.addOrCondition('u_ref_wednesday', parentSysId); detailGr.addOrCondition('u_ref_thursday', parentSysId); detailGr.addOrCondition('u_ref_friday', parentSysId); detailGr.addOrCondition('u_ref_saturday', parentSysId); detailGr.addOrCondition('u_ref_sunday', parentSysId); detailGr.query(); // Loop through all found detail records and update their u_assigned_to field while (detailGr.next()) { detailGr.u_assigned_to = newAssignedTo; detailGr.setWorkflow(false); // Prevents the update from triggering other business rules unnecessarily detailGr.update(); } })(current, previous);
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
after update BR is the answer.
On "u'actual_times_detail" table write the after update BR and glide the another table and update the values.
Please mark the answer correct/helpful accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
I have created a BR for 'after' in u'actual_times_tail, but I cannot obtain the sys_id for u'actual_times_tail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @shiz
Below demo code will help :-
Use an After Update Business Rule on the u_actuant_times table.
When u_assigned_to changes, update the same field in related records of u_actuant_times_details.
Example:
(function executeRule(current, previous) {
if (current.u_assigned_to.changes()) {
var gr = new GlideRecord('u_actuant_times_details');
gr.addQuery('u_ref_Monday', current.sys_id)
.addOrCondition('u_ref_Tuesday', current.sys_id)
.addOrCondition('u_ref_Wednesday', current.sys_id)
.addOrCondition('u_ref_Thursday', current.sys_id)
.addOrCondition('u_ref_Friday', current.sys_id)
.addOrCondition('u_ref_Saturday', current.sys_id)
.addOrCondition('u_ref_Sunday', current.sys_id);
gr.query();
while (gr.next()) {
gr.u_assigned_to = current.u_assigned_to;
gr.update();
}
}
})(current, previous);
This keeps both tables in sync whenever the Assigned To changes in the main table.
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
how are both the tables linked?
what did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
