- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2019 03:36 AM
Hi, I have a table form ABC and its child table form XYZ. I want to write a BR script on the parent table form that if there is a specific field value in the Parent table and there are specific field values in Child table form, the Parent Table form should not be updated.
I know we can dot walk to variables of parent table from the Child table using the keyword "Parent". Now how to dot walk to the Child table variables from the parent?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2019 09:21 AM
here is an example ... in a business rule on the parent:
var gr = new GlideRecord ('table_name'); //child table name
//get all children where the ref field is the sysid of the parent
gr.addQuery('child_table.ref_to_parent_field', current.sys_id);
gr.query();
while (gr.next()){
these are all the children of the record you are currently on
do what you need to do
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2019 03:39 AM
you cannot "dot walk" from parent to child.
there could be multiple children.
you need to write a script to get the children,
loop through the records
look for your value on one specific record or on all children (not sure what you need here)
return a value or indicator to the calling script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2019 03:59 AM
Hi, thanks for replying. Could you please guide me about how to proceed with the script? I needed dot walking to write the script only. Any ideas?
Thanks for replying
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2019 09:21 AM
here is an example ... in a business rule on the parent:
var gr = new GlideRecord ('table_name'); //child table name
//get all children where the ref field is the sysid of the parent
gr.addQuery('child_table.ref_to_parent_field', current.sys_id);
gr.query();
while (gr.next()){
these are all the children of the record you are currently on
do what you need to do
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2019 11:59 PM
Thank you. I was out in vacation so didnt notice. Will try it and return to comment here again. Hope it works!
P.S. the point where you wrote "child_table.ref_to_parent_field", the child table is, suppose, Work Order.
Now, on that child table, there is a field "HSSE" which needs to be non-zero AND the parent table's State field needs to have choice "RTB" in it for us to be able to update the parent form.
So is this correct that the query is "child_table.ref_to_parent_field"...?
============================================================================================================================================
======================================================================
======================================================================
============================================================================================================================================
My code so far:-
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord ('wm_task'); //child table name
gr.addQuery('');
//get all children where the ref field is the sysid of the parent
gr.addQuery('wm_task.parent', current.sys_id);
gr.query();
var str;
while (gr.next()){
}
})(current, previous);