For reports it is a bit easier as you can use << Get Data Table (annoying part is getting the platform reference). Oversimplified examples
get_reference_table_window = Function({reportwindow}, {Default Local},
table = Empty();
tablelist = Get Data Table List() << get name;
window_title = reportwindow << Get Window Title;
table = Empty(); // one should definitely match...
For Each({tablename}, tablelist,
If(Starts With(window_title, tablename),
table = Datatable(tablename);
break;
);
);
return(table);
);
get_reference_table_helpkey = Function({reportwindow}, {Default Local},
table = Empty();
// look for OutlineBoxes with helpKey xml attribute
obs = reportwindow << XPath("//OutlineBox[@helpKey]"); // can run out of depth, could also loop over outlineboxes
objs = obs << Get Scriptable Object;
For Each({obj}, objs,
If(Is Empty(obj),
continue();
);
sobj = obj << Get Scriptable Object;
If(!Is Empty(sobj),
table = sobj << Get Data Table;
);
);
return(table);
);
For data tables it does get more messy and can only rely on name and source table script for non-linked tables. For linked tables you have some more involved strategies you can try.
-Jarmo