Building a defined related list using queries from another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2015 09:09 PM
So right now, I'm trying to build out a defined related list who's construction depends on multiple tables. There currently exists a many to many relationship between two tables, and I'm trying to leverage that table to show all the records that are associated with another record that is assigned to a user. To make it more clear:
User is assigned to Table 1 Record 1
Table 1 Record 1 is associated to Table 2 Record 1, 2 and 3.
I would like a related list on the User table that shows Table 2 Record 1, 2, and 3
So my current idea is to query Table 1 for records assigned to the user.
Then I try to use that data to query the M2M table that exists between Table 1 and Table 2 for records containing the correct reference back to Table 1 as determined by the first query.
Those records SHOULD be the exact records that need to be displayed in the Related List on the User record.
My code for this is below, but I could be fundamentally wrong in my approach. My problem is there is not a lot of documentation on scripting in defined related lists, and how exactly it works. The parent is the user record that the list is being generated for.
var gr=new GlideRecord('u_key_table');
gr.addQuery('assigned_to', parent.sys_id);
gr.query();
var areaIDArray=new Array();
while(gr.next()){
areaIDArray.push(gr.sys_id.toString());
}
var areaIDStr=areaIDArray.join();
current.addQuery('keys', 'IN', areaIDStr);
Any help would be hugely appreciated!
Some clarification: The above code doesn't actually work to bring up the correct records. I'm not entirely sure why, and it's one of a number (although probably the best) of different approaches I took at the problem. The result is always the same: Only one record is returned, ever.
Okay, final edit: I've gone back to the problem and tried it again. Last night, the code would not work at all, despite browser history being cleared, flushing the cache, whatever. This morning, I went to add the related list back to the form (I had taken it off last night in order to demo the system this morning), and when I went to add it back onto the form this morning to test it, it wasn't there. The relationship still existed, and all I did was look at the relationship record and save it... when I went back to the user table, the related list was again available, and it was actually working. I have NO IDEA what made it start working, and now if anyone has any insight into why it would not work, and then suddenly start working, that would be hugely appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2015 10:12 AM
Hi Benjamin,
That's odd, but without delving into the log files and trying to recreate the problem I can only say "that shouldn't happen."
If you run into that issue again int he future, open up an Incident in Hi, so Support can troubleshoot while the issue occurs. They should be able to determine the root cause and open a Problem if the resolution requires a Platform-level change.
Thanks
Cory