Row_Inserting/Updating server event (v2023)

Hi

Using v2023.13

I have setup a Master/Detail page

Master table is epsilon
Detail table is epsilon_comments

So a logged in user can add comments against a master record in epsilon and that all works fine and updates the detail page as expected

I want to add who made the comment

so for the epsilon_comments table in Server Events\Tabel\Specific\ Row Updating

I added

 $myResult = ExecuteStatement("UPDATE epsilon_comments SET who='test'");// Row Updating even   // Enter your code here
    // To cancel, set return value to false
    return true;

Before I try and add CurrentUserID() I thought I would test just using text ‘test’

So no errors but the who field does not get updated ?

Sure I’m making a basic error ?

Kind Regards
John B

  1. you should do this in the row_updated() event… that way you’re assured the records were inserted/updated successfully. if an error occurs and the record isn’t updated… you’ve updated the detail record
  2. you have no WHERE filter
  3. try Execute($sSql)

post you full update code

Hi

Thanks so I will add in Row updated as suggested

Given that I want the person who adds the comment to be added to the who field
what would I set Where to ?

Lastly add an execute like this Execute($sSql)

$myResult = ExecuteStatement(“UPDATE epsilon_comments SET who=‘test’”);// Row Updating even // Enter your code here
// To cancel, set return value to false
return true;

 Execute($sSql)

sorry if im being a bit slow

John

For modifying field contents before adding a record, you should use the Row_Inserting event.

function Row_Inserting(?array $oldRow, array &$newRow): ?bool
{
    $newRow["who"] = 'test';
    // To skip/cancel, set return value to null/false
    return true;
}

Hi

So real progress

I have added this to Row_Inserting

function Row_Inserting(?array $oldRow, array &$newRow): ?bool
{
    $newRow["who"] = 'test';
    // To skip/cancel, set return value to null/false
    return true;
}

I replaced ‘test’; with CurrentUser(); and again it works as expexted

so my last bit is to add the name of the current user
so added this

{
    SetClientVar("login", ["currentUserName" => CurrentUserInfo("FirstName") . " " . CurrentUserInfo("LastName")]);
}

Followed by

{
    $newRow["who"] = currentUserName();
    // To skip/cancel, set return value to null/false
    return true;
}

and it failed but I think Im close

Kind Regards
John B

So I have this in Row_Inserting

function Row_Inserting(?array $oldRow, array &$newRow): ?bool
{
    $newRow["who"] = SetClientVar("login", ["currentUserName" => CurrentUserInfo("FirstName") . " " . CurrentUserInfo("LastName")]);


    // To skip/cancel, set return value to null/false
    return true;
}

So whilst it does not fail it does not update the field who with the actual First and Second name as needed

If I use

function Row_Inserting(?array $oldRow, array &$newRow): ?bool
{
    $newRow["who"] = CurrentUserID(); 


    // To skip/cancel, set return value to null/false
    return true;
}

it sets who to the user _ID so the overall approach does work just need a pointer around how to get the first and second name please

Kind Regards

John B

You should post your related tables schema for more discussion.

As a reminder

U have setup a Master/Detail page
Master table is epsilon Detail table is epsilon_comments
So a logged in user can add comments against a master record in epsilon and that all works fine and updates the detail page as expected
I want to add who made the comment only logged in users can.
so for the epsilon_comments table in Server Events\Tabel\Specific\ Row Updating

The following works but simply populates the who field with a number and I want to populate with the logged in users name?

function Row_Inserting(?array $oldRow, array &$newRow): ?bool
{
    $newRow["who"] = CurrentUserID(); 


    // To skip/cancel, set return value to null/false
    return true;
}

So what do I replace CurrentUserID();
with to get my result, thanks for all the help so far.

Kind Regards
John B

Just make a lookup for who field refer to the users table id field will do.

Hi

How would I go about this ?

Kind Regards

John

If the who field type is not numeric/integer, then you may change it to:

$newRow["who"] = CurrentUserName();

All working as required

Thanks to all who helped

Have a Great 2025

John B