Entity method

Hi All,

I 'm using entity method (new feature in Servoy 6), I have a following method in ‘timesheet’ scope:

function loadTimesheetsByFilter(contact_id, fullyear_filter, status_filter) {
	if (timesheet.getFoundSetFilterParams("timesheet_filter")) {
		timesheet.removeFoundSetFilterParam("timesheet_filter");
	}

	timesheet.addFoundSetFilterParam("contact_id", "=", contact_id, "timesheet_filter");
	timesheet.addFoundSetFilterParam("fullyear", "=", fullyear_filter, "timesheet_filter");
	timesheet.addFoundSetFilterParam("status", '=', status_filter, "timesheet_filter");
	timesheet.loadAllRecords();
}

But after calling this method in a form (datasource of this form is also ‘timesheet’), I ‘m getting this error:"Cannot addFoundSetFilterParam to related foundset’.

Any suggestion?

Thank you,
Mina

Hi Mina,

Your timesheet foundset is probably showing through a related tabpanel.
The addFoundSetFilterParam method does not support related foundsets (Which are already permanently filtered)
The problem you have is that on an entity method, you won’t know which instances are going to be related foundsets.

It is probably better to just run a find in your method and key in your search params.
You can see more on this topic in the Working with Data guide

The difference between a find and a filter is that the filter will be in affect until it is removed, where as a find will be removed the next time loadRecords() or find() is called.

Hpoe this helps,
Sean

Thank you, Sean.
I 'll try this way.

you can ask the foundset/entity if it is build on a relation just ask in an entity method for its “getRelationName()” relation name.