addFoundSetFilterParam

Maarten:

I already use multiple keys in the relationship. I use contactid and a global set to 1, 2, 3, or 4 - depending on the kind of address it is: Office, Home, Second Office, Second Home…

However I set it up the way you suggested:

CONTACTS contact_id~gUser_id :: ADDRESSES contact_id~user_id

So it should look something like this:

controller.addFoundSetFilterParam(‘contacts_to_address.user_id’, ‘=’, globals.gUserID);
controller.loadAllRecords();

Trying to trigger this from the base form does not work.

Neither does it apparently trigger from the child form aka tabpanel?

Any other ideas?[/quote]

John,

  1. UNQUOTE THE RELATED STRING!

SHOULD BE:

controller.addFoundSetFilterParam(contacts_to_address.user_id, '=', globals.gUserID);
controller.loadAllRecords();

NOT:

controller.addFoundSetFilterParam('contacts_to_address.user_id', '=', globals.gUserID);
controller.loadAllRecords();

Note the single quotes around the related string!

Will not work in either direction…

I’ve tried every combination possible running from the onShow or a separate method from the parent/base form or running from a method or onShow in the tabpanel of the child form (obvioulsy reversing the relation).

What else do you have for me?

what I was trying to say is to NOT use addFoundSetFilterParam on a related foundset.
You should let the relation it self do the work for you.
Based on prev info your relation would look like:
CONTACTS contact_id~gUser_id~gaddresstype :: ADDRESSES contact_id~user_id~addressType

When using this relation on the tabpanel , the proper related records will already show up without any scripting

any comments on addTableFilterParam ?

Should I move that to the Feature Requests section?

I need to make a addFoundSetFilterParam that limits the view of our contact database for a specific purpose. Our contact database contains people from several dept’s and the relation is as follows:

member_to_group_member.group_member_to_dept.dept_name

I want to only show contacts who are a member of the “Genetics” dept so I coded this in:

var limit2 = controller.addFoundSetFilterParam(member_to_group_member.group_member_to_dept.dept_name, '=', 'Genetics')

I also tried:

var limit2 = controller.addFoundSetFilterParam('member_to_group_member.group_member_to_dept.dept_name', '=', 'Genetics')

Is there something wrong with my approach, or is this not possible? The filter does not seem to be doing anything.

addFoundSetFilterParam is only supported on columns of the foundset table.

I think best way to go would be scripting the SQL query on pk’s, which you can use again to load a foundset.
pseudocode
dataset = databasemanager(…do query returning pk’s)
loadRecords(dataset)

Let me get this right:

method A
var success = controller.addFoundSetFilterParam('customerid', '=', 'BLONP');
controller.loadAllRecords();

Works on any form based on the table…unless you use a useSeparateFoundSet.
It only works with the search options of Servoy itself.

But it doesn’t work anymore when after method A you use this method

Method B 
var query = 'SELECT customerid FROM customer WHERE customercity LIKE 'Whatever%';
var dataset = databaseManager.getDataSetByQuery('assyst', query, null, -1);
controller.loadRecords(dataset);

Becoz according to the tutorial it says that the only way to remove controller.addFoundSetFilterParam on a form is going to designer-mode.

I found out if you run this code after Method A

var query = 'SELECT customerid FROM customer WHERE customercity LIKE 'Whatever%'; 
var dataset = databaseManager.getDataSetByQuery('assyst', query, null, -1); 
controller.loadRecords(dataset);
controller.sort('customerid desc');

it returns a foundset that is true for controller.addFoundSetFilterParam and the query.

Is this expected behaviour…or a bug

This is EXPECTED behaviour - and is really a feature (I think, anyway).

Why? Becuase when you use a foundsetFilterParam and you load records into the current foundset (with controller.loadRecords) - and you sorted by PK - then you “trigger” the filter.

When you don’t sort by PK and you load the records into the foundset - it just loads the records. In effect, you’ve “overridden” the filter.

Check the “move sample” on load records - and you’ll see that one of the examples is loading the recordset via a sql query - and you’ll see that an “order by” clause is required.