CurrentUserName() selection

I have a table with records. Each time a user creates a record it sends an email to a group email. Any user of the group can login and double check the record and edit (approve) the record using a drop down menu.The current issue is that any user can approve the record and then they have the option to select other members as the "approved by"I would like for that “approved by” dropdown menu to only load the current user that it is logged in when the record is added or edited.I am running the latest version of PHPMaker.

napiedra wrote:
I would like for that “approved by” dropdown menu to only load the current user that it is logged in when the record is added or edited.Then you need to store the user when the record is added or edited first.For example, you may create another table to store the user who add or edit the record, e.g. using Row_Inserted and Row_Update server event to execute INSERT or UPDATE statement to the table.Then you can use the table as lookup table for your dropdown field, set a lookup table filter to filter the records in the lookup table by the id of your record in the main table.

You may simply define your own filter string from “Fields” setup → “Lookup Table” → “Filter” in order to display only your desired option, for example:(CurrentPageID() == “add” || CurrentPageID() == “edit”) ? “your own filter string goes here …” : “”

I tried the following based on the last post:I clicked on the lookup table and on the field setup I selected the User table, selecte the linked field as “ContID” and on the filter I added the follwing:(CurrentPageID() == “add” || CurrentPageID() == “edit”) ? "“ContID=CurrentUserID()” : ""Right when I go to the table I get the following error on the right cornererror: Failed to execute SQL. Error: Unknown column ‘CurrentUserID()’ in ‘where clause’ (1054)Any help would be appreciated!

Try this (assume ContID field is numeric/integer field type):(CurrentPageID() == “add” || CurrentPageID() == “edit”) ? "ContID= " . CurrentUserID() . “” : “”

Hello,FYI your assumption is right, ContID is an INT value. But unfortunately I am still getting an error. Here is the error I am getting now:=================Failed to execute SQL. Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘’ at line 1 (1064)

Have you already enabled “User ID Field” from “Security” → “Advanced” → “User ID”?

Yeah, that fixed it. Thank you very much…

I discovered an issue with this configuration. The filter works and the person who add a record or edits a record can only see his/her username on the drop-down menu for that field. The problem now is that when a different user logs in and edits that records, even when they do not want to edit that particular field, the field comes up empty and it is save as empty after edited.

What can be a possible solution to this?

napiedra wrote:

The problem now is that when a different user logs in and edits that records, even
when they do not want to edit that particular field, the field comes up empty and
it is save as empty after edited.

Then you should filter the recordset only for the current logged in user by using “Recordset_Selecting” server event.

Alternatively, if you want to keep displaying the recordset to other users, you may simply use “ListOptions_Rendered” server event in order to hide the “Edit” (pencil icon) so that your end-users cannot edit the records that do not belong to him/her.

mobhar wrote:

Then you should filter the recordset only for the current logged in user by using “Recordset_Selecting” server event.

I removed the filter from the “lookup table” section.
I am trying to do use the server event “Recordset_Selecting” but the filter is not working. I can see all the users in the user table:

The user table id is ContID. The field name is Approved_by.

// Recordset Selecting event
function Recordset_Selecting(&$filter) {

if (CurrentPageID() == “edit”) {
ew_AddFilter($filter, “Approved_by = '”.CurrentUserName().“'”);
}
}

Another way to look at this same issue, I think it could be simpler to accomplish…

In the same table I have a record called “Approval” and another record called “Approved_by”

Is there a way to check for the “Approval” field and if Approval == 1 (approved) then make the field “Approved_by” read only?

From your first post above, you mentioned you are running the latest version of PHPMaker, but in “Recordset_Selecting” server event you are still using the older “ew_AddFilter” that is not used anymore in the latest version.

You should use “AddFilter” instead.

Please read “Migrating to v2020” from https://phpmaker.dev/doc/migrate2020.htm

napiedra wrote:

Is there a way to check for the “Approval” field and if Approval == 1 (approved)
then make the field “Approved_by” read only?

Simply put the following code in “Page_Render” under your “Edit Page”:

if ($this->Approval->CurrentValue == “1”) {
$this->Approved_by->ReadOnly = TRUE;
}

This worked perfectly, I hope other could benefit from this post.