How to access parent object within "query from" of relationship
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2018 12:34 PM
I am trying to create a scripted defined related list on a table which will display records from different archive tables based on a field value on the parent table. I am doing something like this.
Apply to: a particular table
sample statement: answer = "target_table";
Query from: Scripted
Sample statement:
var table = "ar_" + parent.u_select_table.toString();//u_select_table is a field on the "target_table" which contains a table name
answer = new TableUtils(table).tableExists() == true?table:false;
What I am suspecting is that the parent object is not accessible within "Query from" script. So, is there a way I can populate the "query from" table dynamically based on current parent record's field value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2018 04:42 PM
Hi Subhrajit,
Were you able to accomplish this? I have the exact same requirement.
I have a need to dynamically select "query from" table based in choice selection on "parent" record.
Please let me know.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2018 05:10 PM
I am still looking for a solution and will update this post if I find anything. However, please feel free to share if you find a solution.
Regards,
Subhrajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2018 06:04 PM
I have found a solution to the issue. Please try and let me know if it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2018 06:03 PM
I have finally found a solution to this. Here is the detail.
Step 1: Create/modify an on-display business rule on target table <target_table> where you want the related list to load by storing the current record's table name to a session variable.
function putSessionData() {
var session = gs.getSession();
session.putClientData('sourceTable',current.u_select_table);//u_select_table is a field which contains the table name
}
Step 2: Modify the "Apply to" and "Query from" scripts of the scripted relationship as below
Apply to:
answer = table_name == "<target_table>"?true:false;//Ensure the related list appears only on the target_table.
Query from:
var session = gs.getSession();
answer = session.getClientData('sourceTable');//Based on target_table's u_select_table field which contains a table name
To limit which records to fetch from the source table, modify "Query with" script like below
(function refineQuery(current, parent) {
// Add your code here, such as current.addQuery(field, value);
var queryString = "<encoded_query>";
current.addQuery('sys_id','IN', queryString);//current is the source table, parent is the target table
})(current, parent);
As the on-display BR will run before the related list is loaded, this solution will work and using the session variable will ensure it applies to current user session only.