[Resolved] FID not loading selected record

I am using the following code to open a form in dialog from a form in tab but the record selected is not loading in the dialog. What have I done wrong?

function btn_Edit()
{
//select the right row
forms.dlg_address.foundset.selectRecord(forms.lst_project_address.address_id)	
//show the dialog
application.showFormInDialog( forms.dlg_address)
//Start Transaction
databaseManager.setAutoSave(false);	
}

Thanks in advance.

foundset.selectRecord(id) only selects records that are already in the foundset, so if your dialog form has a different foundset than the other form, it doesn’t always work.

Another way to do what you want is to just load the right record on the form:

function btn_Edit()
{
	//load the right row
	forms.dlg_address.foundset.loadRecords(databaseManager.convertToDataSet([forms.lst_project_address.address_id]));
	//show the dialog
	application.showFormInDialog( forms.dlg_address)
	//Start Transaction
	databaseManager.setAutoSave(false);   
}

Thanks that worked a treat. I tried this to open a contact in a form from a table in a tab and it filtered the contacts to show 1 of 1. Can it open the selected contact and show the usual 200+ foundset?

If you want to load in the FID the same foundset of the main form use this:

forms.dlg_address.loadRecords(forms.lst_project_address.foundset)

The selected record will be the same as in your lst_project_address form so if you are on record number 3 of 200 in the list and open the FID you will see record number 3 in the FID but you will be able to navigate the other 199 records as well (using ALT UP and ALT DOWN for instance).

Thanks Nicola. I have tried using the information Joas and yourself has provided in a similar situation, opening a contact form (not a dialog) from a record in a related table from a tab with no luck. The incorrect contact is current when the contact form is displayed.

I even hijacked the following from the example servoy crm with the same result.

forms.lst_project_people.foundset.selectRecord(contact_id);
forms.frm_contact.controller.show(forms.frm_contact);

Any ideas why this would not be working?

Try this instead:

forms.lst_project_people.foundset.selectRecord(contact_id);
forms.frm_contact.controller.loadRecords(forms.lst_project_people.foundset);
forms.frm_contact.controller.show()

Nicola,
error: Cant set a foundset from table project_people into a form using table contact. :?

I’m not sure what you’re trying to achieve, I think you should explain it a little more.

A couple remarks though:
The “lst_project_people”-form is based on the “project_people”-table
The “frm_contact”-form is based in the “contact”-table.

A form that is based on a certain table can only display records of that table, so you can’t load a “project_people”-foundset on a “contact”-form.

If you do selectRecord() on a form, the argument should be a primary key of the table the form is based on, so doing forms.lst_project_people.foundset.selectRecord(contact_id); makes no sense.

Joas:
I’m not sure what you’re trying to achieve, I think you should explain it a little more.

A couple remarks though:
The “lst_project_people”-form is based on the “project_people”-table
The “frm_contact”-form is based in the “contact”-table.

A form that is based on a certain table can only display records of that table, so you can’t load a “project_people”-foundset on a “contact”-form.

If you do selectRecord() on a form, the argument should be a primary key of the table the form is based on, so doing forms.lst_project_people.foundset.selectRecord(contact_id); makes no sense.

The project_people table has the following fields, project_people_id (pk), project_id, contact_id (fk)…and some others. There is a relation contacts_to _project_people so when I am in the contacts form I can see a list of projects the contact is associated too. There is a projects_to_project_people relation to show the contacts related to the project. In the lst_project_people form in the tab I would like to be able to select the contact in the row and pass the contact_id to the contact form and show that contact.

ok, well in that case I think you should do:

forms.frm_contact.foundset.loadRecords(databaseManager.convertToDataSet([forms.lst_project_people.contact_id]));
forms.frm_contact.controller.show();

The first line gets the contact_id of the currently selected “project_people”-record in the “lst_project_people”-form, converts that to a dataset, and does loadRecords(dataset) on the “frm_contact”-form. If you do loadRecords(dataset), Servoy will get all the values of that dataset (only that one contact_id in this case) and loads the records that have one of those values as their pk (only one record in this case).

The second line shows the “frm_contact”-form.

Thank you Joas & Nicola.