Custom script to fetch data from one table to another


I have created a custom DocType, Position. There are two tables in Position, each linked to custom DocTypes - custom-role and custom-authorization_rule.

The 1st table is linked to custom-role. I need to link this to the 2nd table, such that it generates the custom-authorization_rule(s) for the role(s) selected in the 1st table.

Is there a custom script the fetch the role from the 1st table, into the 2nd table, to populate the rules?

Any advice please.
Thank you.

@fachristy, no, no have a custom script, but nothing that a forEach cannot resolve!