Filter records by CurrentUserID()

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
merlin
User
Posts: 14

Filter records by CurrentUserID()

Post by merlin »

Is there a way to filter records on list/edit/view by the CurrentUserID() - so I do not have to create a View for every CurrentUserID() or by part of it

e.g
telesales userid = ES-M01-T01, ES-M01-T02, ES-M01-T03 etc
manager userid = ES-M01

ES = country (spain)
M01 - manager 01
T01 - telesales person 01

So I need to filter on ES-M01-T01 but if I log in as ES-M01-T02 they can not see any records stamped by ES-M01-T01

Or I may login as ES-M01 - "manager" and want to filter all telesales persons ES-M01-T01 and ES-M01-T02 etc but cannot see any records for ES-M02 etc

Regards
Martyn


mobhar
User
Posts: 11746

Post by mobhar »

Use Recordset_Selecting server event. Assume the user id field name is "MyUserIDField" and its type is integer/numeric:

function Recordset_Selecting(&$filter) {
ew_AddFilter($filter, "MyUserIDField = ".CurrentUserID().""); // Adjust "MyUserIDField" with yours
}


merlin
User
Posts: 14

Post by merlin »

The Field I update in my table by setting it to CurrentUserID() is VARCHAR and gets set to "ES-M01-T01" or ES-M01" is there a reason you say "Assume the user id field name is "MyUserIDField" and its type is integer/numeric:"


mobhar
User
Posts: 11746

Post by mobhar »

Then try this:

function Recordset_Selecting(&$filter) {
ew_AddFilter($filter, "userid = '".CurrentUserID()."'"); // Adjust "userid" with yours
}


merlin
User
Posts: 14

Post by merlin »

Tried this it masked out all my records - no records shown

JUst wondered if - Lookup_Selecting could be the better option - but I am rather a newbie at this stuff

Example 2

Add filter to the lookup table filter

function Lookup_Selecting($fld, &$filter) {
if ($fld->FldName == "MyLookupField")
ew_AddFilter($filter, "MyField = 'xxx'"); // Assume the field is of string type
}

I am trying to figure out what the difference between "MyLookupField" & "MyField" is


merlin
User
Posts: 14

Post by merlin »

Solved the issue

// Recordset Selecting event
function Recordset_Selecting(&$filter) {
// Enter your code here
ew_AddFilter($filter, "LastUserToUpdate = '".CurrentUserName()."'");
}

This Filters only records by Current User Name

Many thanks for pointing me in the right direction "mobhar"


danielc
User
Posts: 1601

Post by danielc »

If you use User ID Security feature, you can setup a parent user id field like "ReportsTo". If telesales user is setup to report to manager, manager will be able to see the subordinate record. See Tutorial - Advanced Security - User ID Security in help file.


Post Reply