Hi All, could someone help me with the right code here please. I have a form for users to fill in. The last Drop-Down field on this form is 'Report Status' where user can select two options (Complete & Incomplete). What I need is when user select the status 'Complete', the owner of the record will change to another owner (in admin group) so this record will no longer be editable by original owner.
I've browsed the forum inside out, but cant find anything, apart from quick answers like (can be done through something..)
I'm not an expert in writing code from scratch, but if someone could generate a simple code as an example from above scenario, I would greatly appreciate that. I'll pay $25 to PayPal account for the code that does this task. (can't pay any higher, as I'm not earning anything from this )
Thanks in advance!
Record owner change when selecting status field: Complete
- aarlauskas
- Veteran Member
- Posts: 127
- Joined: 2019-04-28 18:03
- Location: Medway, UK
Re: Record owner change when selecting status field: Complete
Hi ,
you can try to add this to the hooks/"TABLENAME".php file in the after_insert ( and maybe the after_update) function
where NEWOWNER is the memberID of the new owner, GROUPID is the groupID of your admin group and TABLENAME is the tablename you put the code in
you can try to add this to the hooks/"TABLENAME".php file in the after_insert ( and maybe the after_update) function
Code: Select all
sqlvalue("update membership_userrecords set memberID = 'NEWOWNER', groupID=GROUPID where pkvalue=".$data['selectedID']." and tableName='TABLENAME'");
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: Record owner change when selecting status field: Complete
Just to add, bevor executing the sql query you need of course to check the result of your Drop-Down.
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: Record owner change when selecting status field: Complete
Open the file hooks/TABLENAME.php and modify the TABLENAME_before_update() function:
* replace TABLENAME by the name of your table.
Kind Regards,
Jan
* replace TABLENAME by the name of your table.
Code: Select all
function TABLENAME_before_update(&$data, $memberInfo, &$args)
{
$tablename = "TABLENAME"; // change this
$newowner = "admin"; // change this
$id = $data["selectedID"];
$report_status = $data["report_status"]; // if this is a lookup you will need an additional sql query here.
if ($report_status === "Complete") {
set_record_owner($tablename, $id, $newowner);
} else {
// perhaps there is need to re-assign the owner on a different Report Status
}
return TRUE;
}
Jan
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools