Hi,
I have 1 parent record with many child records. Is it possible to display these related child records in tabpanels dynamically ???
Hi,
I have 1 parent record with many child records. Is it possible to display these related child records in tabpanels dynamically ???
Do you mean by “dynamically” that if you change the parent, the tab will only show the children of thát parent?
The only thing you have to do for that, is place the tab through the “parent_to_child”-relation, Servoy takes care of the rest.
Hi Joas,
Joas:
Do you mean by “dynamically” that if you change the parent, the tab will only show the children of thát parent?The only thing you have to do for that, is place the tab through the “parent_to_child”-relation, Servoy takes care of the rest.
Thanks for the reply,
I would like to display each child record in a record view in its own tab. I hope that makes sense.
Hi phil,
So lets say your parent record has 3 child records then you want it to automatically create 3 tabs with each a (record) view on that specific child record? Is that what you want ?
I think that can be done with creating new form instances and adding tabs but what if a record has 1000 child records, do you want 1000 tabs then ? Maybe a better approach would be to have a (perhaps custom) controller in 1 tabpanel and scroll though the children in record view ?
Hope this helps.
Hi Robert,
So lets say your parent record has 3 child records then you want it to automatically create 3 tabs with each a (record) view on that specific child record? Is that what you want ?
Yes
Tab panels is really what I am after, in this case I would limit the amount of related records that could be created eg. 1 Quote can only have 30 worksheets, etc.
I think that can be done with creating new form instances and adding tabs
//Create a new form instance
var ok = application.createNewFormInstance('_workorder_data_entry',null);
if (ok == true)
{
forms._workorder_holder.elements.tabs_workOrders.addTab(forms['_workorder_data_entry'])
}
I have the above code but no luck ? any ideas I am unsure how to use the ```
application.createNewFormInstance
Hi Phil,
The application.createNewFormInstance() function requires 2 parameters, the first one is the name of an existing form you will be using as a template.
And the last parameter is the name you give to this new instance.
Also make sure your template form has the useSeperateFoundset property checked since you want all the instances to show different foundsets.
And you need to load the correct record in each of the form instances as well.
I think your code will look something like this:
var bOK,
rc,
fs = forms._workorder_holder.childRelationName,
nMaxRecord = databaseManager.getFoundSetCount(fs);
// NOTE: change relationname accordingly
for ( var i = 1 ; i <= nMaxRecord ; i++ )
{
bOK = application.createNewFormInstance('_workorder_data_entry', 'workorder_data_instance_' + i);
if ( bOK ) {
rc = fs.getRecord(i);
forms['workorder_data_instance_' + i].controller.loadRecords(databaseManager.convertToDataSet([rc.id])); // load PK field
forms._workorder_holder.elements.tabs_workOrders.addTab(forms['workorder_data_instance_' + i])
}
}
Hope this helps.
As Roclasi explained it is possible to do this using multiple form instances, adding the tabs yourself and make sure that the right records are loaded.
But in my opinion, you’ll make it a lot easier for yourself if you just use one form and fake the tabs using a number of labels on top that you show/hide depending on the number of child records. Give each of those labels a name containing a number and use one simple method to set the selectedindex based on the number in the methodTriggerElementName().
Joas:
But in my opinion, you’ll make it a lot easier for yourself if you just use one form and fake the tabs using a number of labels on top that you show/hide depending on the number of child records. Give each of those labels a name containing a number and use one simple method to set the selectedindex based on the number in the methodTriggerElementName().
That kinda is what I suggested in the first place. It’s definatly a much ‘lighter’ solution than creating new form instances.
Thanks for all your suggestion guys, I am going to do some testing
Hi!!
I can add one parent record with many chield records in a tab panel whith a relation??
Hi ahurtado,
ahurtado:
I can add one parent record with many chield records in a tab panel whith a relation??
If you are asking if you can add a tab to a tabpanel with a relationship the answer is yes.
See the addTab function of a tabpanel.
Hope this helps.
ok, thanks
what i’m trying to do is:
I have a parent form with a tabPanel for the children, the form in the tabPanel is linked to a relation, i’m trying to add a new parent with its children inside a transaction with the autosave set to “false”. the problem is when i’m about to save i set a value for the children by code wich can’t be null, but just in the save moment i get an error because that value is null, it seems that value never was set, and i think Servoy is saving the children first than the parent
my question is:
How does work databaseManager.saveData() inside a transaction?
how do you create those new child records?
through the relation?
Thank!!
I resolved the problem by placing the primary key managed by the database as in the CRM Demo
But…
How can I have a TabPanel with several forms inside pointing to the same
table and when I add a new record I want to go through the tabs and fill
the several fields inside of each tab and save normaly.
As example, I have a table with more than 20 fields and want to group
and distribute them amoung the tabs in the TabPanel.
I did the following test:
I create a relation based on the table and a global variable, the
dataproviders of the forms (inside the tabs) are based in that
realation. When I navigate through the saved data it works, it shows me
the values of the fields well, but when I try to add a new record those
fields are null and I get an error because of that.
Hi,
Create a form based on the table with no fields on it.
Create a relation from that table (pk) to that same table (pk) ( self-relation) an then place the forms on the different
tabs using that same relation for all the tabs.
We use this construction a lot.
Regards,
and in 4.1 there is even a better way to really have the same foundset in all the tabpanels
create a self relation that is a relation with no keys and pointing to the same table
Can you explain the difference ?
Tia,
with pk → pk you have a self join to 1 record. you have really 2 foundsets
the other way you really have a ‘self join’ to the complete foundset, you really only have 1 foundset that is shared over all the tabpanels.
Ok,
Great stuff !! Servoy gets better and better.
To be sure I understand completely : does that also mean that in 4.1 the number of queries fired on the database is only 1, no matter how many tabpanels there are in the selfjoin ? And in 3.5.x there is one query for every tabpanel in such a selfjoin?
Regards,