Save current username in table

Feature(s) impacted

When saving an object in a table with a DDL “current_date()” default for our “date_created” and “date_updated” columns, we can record when our record is touched.

However, the “created_by” and “last_updated_by” columns in our table are left blank as I cannot find a way to tie together the user logged into the ForestAdmin UI to these columns to persist the name within our database.

Observed behavior

When creating or saving a record via the ForestAdmin UI, we cannot find a way to propagate the session’s username to our database column(s).

Expected behavior

While I’m not expecting what I’m asking to work without some type of configuration, I haven’t found any documentation or help topics that explain how to get the session’s username and write it to a column in the table being created/updated.

The ask is that upon creating/updating, the session’s username will be send to specific columns meant to hold that data.

Please note that this ask cannot be solved by the Activity logs in the UI as we need to persist the user’s name on the record in our database for reporting purposes.

Context

  • Project name: refinition-data
  • Team name: operations
  • Environment name: production
  • Agent (forest package) name & version: SaaS version of Forest
  • Database type: MySQL

Hello @Brendan_Arsenault ,

You will have to customise your admin panel with some code to achieve this behaviour. You can click on the “<>” button on the bottom left of the screen to learn how to implement code customisations on Forest Admin.
image

Then, in your code customisations, you will need to implement an “update” hook on the desired collections.
Please have a look at this documentation to see how to do it: https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/hooks/collection-hook

Kind regards,
Enki

2 Likes