I have a form that sometimes I use as a normal list form, and sometimes as a form displayed in a tab panel from another form and table. On a field in this form is an onAction button to bring up a record form in dialog of other fields pertaining to the record in the table.
Obviously, when the form is used as a list form, the correct record is shown, but when the form is displayed as a tabpanel in another table, the method shows the records from the first record in the file,not the proper related record. How can I code the method so that it will get the correct record regardless of from which form it is called?
I’ve had this struggle as well.
One thing you need to remember about Servoy is “context.” The context you’re in at the moment will determine everything. When you use the listview by itesel - the context is the list view - so the script works. If you show the listview in a tabpanel - then the “context” is that of the master record you’re displaying.
Here’s what I do:
-
Create a global field;
-
The first line in the script of the button set the global field to the primary key of the record you’re clicking on;
-
Create a relation (global key to child database) - and load the record based on that relation.
Now it will work in every context.
Hope this helps,
Bob
Thanks for your quick response!
I don’t know where I’m going wrong!
Attached is the scheme for the forms.
- I’ve created a globals.matterid field
- I’ve created a relation globalmatterid_to_matter from Matter file to Matter file using globals.matterid equals matterid.
- method attached to Matterlist2 form record line:
//viewMaDetail[MatterList2]
globals.matterid=matterid
controller.loadRecords( globalmatterid_to_matter)
application.showFormInDialog( forms.maDetail, -1, -1, -1, -1, “Matter Details” );
Now, when I click on a line from normal list view, the correct record is displayed in dialog, but when the dialog is dismissed the rest of the found set is removed. I underestand how this happens from the loadrecords step in the method, but how do I get my previously found set back?
When I click on a line when the form is displayed in tabPanel (called from form clDetail0) all of the fields in the dialog are blank.
I’m lost in tabpanel hell!
Can you upload (or email) me your solution [bcusick@servoy.com]?
I can help you out.
Bob Cusick
Maybe this approach helps:
In the crm demo there 's a create button in the contactslist that’s attached to this script:
if(currentcontroller.getName() == “companyDetails”)
{
controller.newRecord()
company_id = forms.companyDetails.companiesid
}
else
{
plugins.dialogs.showDialog(‘Alert’,‘Contacts may only be created in Companies’,‘OK’);
}
It simply checks in which main form you are currently in.
(the script will only create a new contact record when you are in
company details. (there’s a tabpanel there "Contacts’ that is actually the same form as contacts list.)
Thanks Maarten, but I think my real problem is not knowing what form I’m in at any point in time, particularly with regard to tabpanels.
For example, in the scheme above, I know when i’m in clList form, when I click on a record line from the list, I switch to clDetail0, but then, when I click on the tab panel for matterlist2, which form am I in? clDetail0 or materlist2?
clDetail0
currentcontroller.getName() always returns the main form you’re in.
(even if you trigger a script inside a tabPanel)