Filter on table with CurrentUserName()

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

Filter on table with CurrentUserName()

Post by Brostin »

Greetings to the Forum,
I need to filter a table on the basis of the user connected to the database. Obviously in the table there is a field where the value of the current user has previously been stored. therefore in the property, in correspondence of the filter, of the table I would put the following description:
"user_ID = ... ".
Thank you


mobhar
User
Posts: 11727

Post by mobhar »

You may simply use "Recordset_Selecting" server event to filter the record based on that CurrentUserName(). Please read "Server Events and Client Scripts" topic from PHPMaker Help menu for more info and example.


Brostin
User
Posts: 64

Post by Brostin »

First of all thank you.
Your suggestion works but I would like to know how I can replace the static comparison value (user_LAG) with the value of the current user.
// Recordset Selecting event
function Recordset_Selecting(&$filter) {
ew_AddFilter($filter, "utente_ID = 'user_LAG''");
// Enter your code here
}
Thanks


mobhar
User
Posts: 11727

Post by mobhar »

Simply change this code:
ew_AddFilter($filter, "utente_ID = 'user_LAG''");

to:
ew_AddFilter($filter, "utente_ID = '" . CurrentUserName() . "'");


Brostin
User
Posts: 64

Post by Brostin »

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

No records Found


mobhar
User
Posts: 11727

Post by mobhar »

Usually, it happens because the current logged-in user is Administrator or another user which their username does not exist in that table. So, double check again your records in that table, and make sure you you have at least one record which has that criteria.


Brostin
User
Posts: 64

Post by Brostin »

Forgive me. In an attempt to solve my problem I had forgotten a value in Advanced Security. Now everything is OK.
Thank you so much, Brostin


Post Reply