How to test the below on Before insert Business Rule Script and please explain ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2022 07:15 AM
function onBefore(current, previous) {
var gr_cf = new GlideRecord('u_causal_factors');
gr_cf.addQuery('u_task_reference',current.u_problem);
//gr_cf.addNullQuery('u_rca');
gr_cf.query();
while(gr_cf.next()) {
gr_cf.u_rca = current.sys_id;
gr_cf.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2022 07:45 AM
Hi
I don't think the way you have written now is a correct way of doing it. Before Insert means you have not inserted a record into RCA table and even before that you are trying to check against that record in another Table named as "u_casual_factors" and trying to update a field in that Table with the sys i of RCA record which I don't think would have been created.
This is incorrect, I believe. Please follow the suggestion below
You need to write this as a After Insert Business Rule on RCA Table and then use the script which you are using.
Script is checking that when you create a Record in RCA Table then you are mapping RCA new record to a field named as "u_rca" based on "u_task_reference" field getting matched against Problem field on RCA Table.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke