Hi everyone.
I would like to set up two queries directly in appgini for two calculated field.
In the first field, which I called "date", I would like the RECORD CREATION date to appear.
In the second field I would like the username of the user who created the record to appear.
Since for particular reasons the new records are generated in "update" mode and not in "create new" mode (ie there is a code that as soon as a user has logged in creates a record for the user and displays it in "update" mode) I can't set date and text fields with default values "<%%creationDate%%>" and <%%creatorUsername%%> but I have to set a query in the fields in "calculated field" mode.
Thanks for your help!
Fabiano
get creation date and creator username of a record by calculated field
Re: get creation date and creator username of a record by calculated field
Hi.
why do you need to do this via calculated fields? As this is a one-time action you could handle it in the update function
check if there is already a "creation user" set, if not set it to the user and set the creation time. Otherwise do nothing.
why do you need to do this via calculated fields? As this is a one-time action you could handle it in the update function
check if there is already a "creation user" set, if not set it to the user and set the creation time. Otherwise do nothing.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: get creation date and creator username of a record by calculated field
thank you so much!
Can you please help me with the code? I'm a learner so is a bit diffisult form me!
Thanks!
Fabiano
Can you please help me with the code? I'm a learner so is a bit diffisult form me!
Thanks!
Fabiano
Re: get creation date and creator username of a record by calculated field
Hi,
this is not possible without knowing your app.
If you need code support, please write me a pm.
this is not possible without knowing your app.
If you need code support, please write me a pm.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: get creation date and creator username of a record by calculated field
Hi fgazza,
I agree with pbötcher on the why are you doing it this way in the fist place, and that it's impossible to help without knowing more details.
I suggest this:
Create created at/by fields as readonly in AG.
Then use php code in the /hooks/tablename.php -> after_insert and after_update and simply add code to write the logged in username and current timestamp to the recored (selected_id).
Note: you need to use after_ as you can not change the data for readonly fields in the hooks.
Get the username:
Get the timestamp:
Just update the record:
(code examples are not tested)
Olaf
I agree with pbötcher on the why are you doing it this way in the fist place, and that it's impossible to help without knowing more details.
I suggest this:
Create created at/by fields as readonly in AG.
Then use php code in the /hooks/tablename.php -> after_insert and after_update and simply add code to write the logged in username and current timestamp to the recored (selected_id).
Note: you need to use after_ as you can not change the data for readonly fields in the hooks.
Get the username:
Code: Select all
$mi = getMemberInfo();
$details = makeSafe($mi['username']);
Code: Select all
$ts = date('Y-m-d H:i:s', strtotime("now"));
Code: Select all
UPDATE `tabelname` SET `createdname`,`createdtime` VALUES ('$details','$ts') WHERE `ID` = ' . makeSafe(SelectedID) .';'
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view