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