How to access the variables of a Child form from a Parent form?

Ashirav
Tera Expert

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?

1 ACCEPTED SOLUTION

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

}

View solution in original post

5 REPLIES 5

ggg
Giga Guru

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.

 

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

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

}

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"...?

============================================================================================================================================

find_real_file.png

======================================================================

======================================================================

find_real_file.png

============================================================================================================================================

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);