Showing related records with showFormInDialog

I have a form, Panels. On that form is a button to popup another form which will display all of the members of the currently selected panel.

To show the form I do:

application.showFormInDialog(forms.panel_members, -1, -1, -1, -1, " Panel Members ")

That part is working fine.

To limit the records displayed in the panel_members form, before the line above I do:

forms.panel_members.controller.loadRecords(panel_members_to_panels2)

When it hits that line I get the following error: Can’t set a foundset from table panels into a form using table panel_members.

The panel_members_to_panels2 relation joins the two tables on the id_panels field.

What am I doing wrong?

is your form: panel_members maybe atatched to the table: panels?

It looks that way

Than your method does not work. You are trying to set a foundset between tow different tables!!

No. My panel_members form is attached to the panel_members table.

Ah now I see,

you are trying to set the form: panel_members with a foundset of: panels.
That is not ppssible.

here is an example of how loadRecords works:

forms.panels.controller.loadRecords(panel_members_to_panels2)

now your are setting the form: panels with the right foundset!

So in yourexample you have to make another relation the other way:

forms.panel_members.controller.loadRecords(panels2_to_panel_member) 

I tied that:

forms.panel_members.controller.loadRecords(panels_to_panel_members)
application.showFormInDialog(forms.panel_members,5,130, 510, 500, " Panel Members ")

It doesn’t give me an error, but it doesn’t do the job either.

When the form opens, all of the panel members, for all panels are showing. I only want to show the panel members for the selected panel.

than you have to check your relation: panels_to_panel_members

it should work this way. I use it alot.

Attached is a picture of the relation window. Let me know if you think I’m doing anything wrong. The primary key of Panels is id_panels plus id_projects.

Thanks.

is the relation valid when you call loadRecords?
try application.output("count "+panels_to_panel_members.getMaxRecordIndex()) to see in your output window how many records are in there before calling loadRecords

Jan,

When I put that line of code in:

application.output("count "+panels_to_panel_members.getMaxRecordIndex()) 
forms.panel_members.controller.loadRecords(panels_to_panel_members)
application.showFormInDialog(forms.panel_members,5,130, 510, 500,  " Panel Members ")

I get an error message: “Cannot convert null to an object”

If I go to Tools/Relations the panels_to_panel_members is listed as part of the panels table but it is not listed in the editor under relations for either the panels_one_member form on which I am clicking or the panel_members form that I want to open.

I’m not sure what to do about it…

gstein:
I get an error message: “Cannot convert null to an object”

Thats what I thougth you are passing null to loadRecords…
You are using the relation from within the wrong form or it is not defined at all (is named different) ,did you move the code? or type it yourselfs?

I created the relation myself.

When I created the one or both of the panel forms, I may have copied a different form and then changed the referencing table and other properties of the controls in the properties window.

Thats not what I mean, in the editor treeview on a form node is a relations subnode, can you move the relation “code” (with move code button) into your script?
Moving code makes sure the syntax is valid and you are accessing it the right way (handy incase you are not sure)

In the editor treeview I have two panel forms, both based on the panel_members table. They both have the same list of relations – but the relation I want is not listed there at all. I can only see the relation I want by going to the Relations window and looking at the Panel (not Panel Members) table.

When I popup the Panel Members form, I want to limit the records to only the related Panel that is currently selected on the Panels_One_Member form.

gstein:
– but the relation I want is not listed there at all. I can only see the relation I want by going to the Relations window and looking at the Panel (not Panel Members) table.

Exactly, this means that relation is not accessible from the that form, the form table must be the same as the left side table from the relation.