Passing Value Form to Form

This is the first time I have attempted this …

I would like to get the value of the companyid field on the current form and pass it onto another form (a dialog). This dialog should then automatically create a new record for the companyproject table setting the companyid field to the one found…then the user can then select the project and the role the company has in the project.

The dialog is then closed and the project shows up in the project tab on the company form.

I have everything working well except the passing of the companyid to the new record created.

I thought I could use the following to get the value when the method to open the dialog is selected…

var companyid = forms.company.elements.companyid

Thanks

hi,

maybe, in the same method, before calling the showformindialog you can create the new record and assign the companyid field to it…

forms.comanyproject.controller.newRecord(true);
forms.companyproject.companyid = companyid; 
application.showFormInDialog( forms.companyproject,....);

but if the company and the companyprojects tables are related by the companyid, servoy will add the relating field for you so you do not have to worry ;)

company_to_companyprojects(true,true);
application.showFormInDialog( forms.companyproject,......);

hope it helps, bye

your first option works well if the company has a project already defined. if no project is already defined there is a “companyid” is not defined error msg.

the second option I get a “null-value is not a function.” error msg.

This is what I have.

forms.projectcompanies.controller.newRecord();
forms.projectcompanies.companiesid = companiesid; 

forms.projectcompanies_dialog.SetButtonDefaults();

application.showFormInDialog(forms.projectcompanies_dialog,-1,-1,-1,-1);

I get the following error when trying to add the first project to a company.

“companiesid” is not defined.
Callstack:
projectcompanies_projectlist.btn_AddProject

[/code]

Looks like it cannot ‘find’ the companiesid to use so you need to establish its location

Try changing your code to the following:

forms.projectcompanies.controller.newRecord(); 
forms.projectcompanies.companiesid = forms.companies.companiesid; 

forms.projectcompanies_dialog.SetButtonDefaults(); 

application.showFormInDialog(forms.projectcompanies_dialog,-1,-1,-1,-1);

So you tell it to use the companiesid which is on the companies form (or whatever the form is named !)

Cheers
Harry

4xjbh:
This is what I have.

forms.projectcompanies.controller.newRecord();

forms.projectcompanies.companiesid = companiesid;

forms.projectcompanies_dialog.SetButtonDefaults();

application.showFormInDialog(forms.projectcompanies_dialog,-1,-1,-1,-1);




I get the following error when trying to add the first project to a company.

I was suggesting something different of what you have tried… Obviously I don’t have the full image of your application … but supposing you are on the form companies, and the form is showing an existing record with a defined companiesid, then from a method based on THIS same form companies you can call instructions that “operates” on the controller of the dialog form before displaying it… something like:

// method defined and executed from form companies
forms.projectcompanies_dialog.controller.newRecord();
forms.projectcompanies_dialog.companiesid = companiesid; 
application.showFormInDialog(forms.projectcompanies_dialog,-1,-1,-1,-1);