Relationship failing in dynamically created form

Hi all,

Servoy 5.1.4, Mac OS X 10.6.3, latest java. PostgreSQL 8.4.

I have a notes panel I use in 8 different contexts. In each context I create a form instance and add it to a tab panel onLoad.

function on_load() {
	if(! forms.person_notes) {
		if (application.createNewFormInstance('crm_notes_list_panel', 'person_notes')) {
			elements.notes_panel.addTab(forms.person_notes, 'Notes', 'Notes', null, null, null, null,crm_people_to_crm_notes);
		}
	}
	forms.person_notes.elements.new_note.text = "New Note";

}

When I test from Developer this fails to filter the notes using the crm_people_to_crm_notes relationship. I get all notes.
If I change to:

function on_load() {
	if(! forms.person_notes) {
		if (application.createNewFormInstance('crm_notes_list_panel', 'person_notes')) {
			elements.notes_panel.addTab(forms.person_notes, 'Notes', 'Notes', null, null, null, null,'crm_people_to_crm_notes');
		}
	}
	forms.person_notes.elements.new_note.text = "New Note";

}

The code works when I test from developer, but fails for 2 out 10 users when I deploy. They get no notes at all.
If I qualify the relationship with a form name it seems to work when testing from Developer.

function on_load() {
	if(! forms.person_notes) {
		if (application.createNewFormInstance('crm_notes_list_panel', 'person_notes')) {
			elements.notes_panel.addTab(forms.person_notes, 'Notes', 'Notes', null, null, null, null,forms.crm_people.crm_people_to_crm_notes);
		}
	}
	forms.person_notes.elements.new_note.text = "New Note";

}

Any ides what to look for?

the first one will not work because your are in an onload.
onload doesnt have data! So the relation you access there is not there yet.
(relations are really access through records so record.relationname is the thing that really happens)

As far as i can see the second solution should work. There you do create a tab with that relation name.

prefixing it with forms doesnt make it any better, as i said relations are got through records
is that “forms.crm_people” that you prefix it with the form that also has that on_load method to his onLoad event?

Better would be to do all this in the onShow (and then use the first time boolean if you want)
then you can also test for example the size of crm_people_to_crm_notes at the time you create the tab.

jcompagner:
the first one will not work because your are in an onload

Oooh. Did not know that.

Will try to move this to the first onShow.

Hi Johan,

just want to say that using the second version inside onShow() seems to have sorted the problem.