Record owner change when selecting status field: Complete

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Record owner change when selecting status field: Complete

Post by aarlauskas » 2019-06-03 18:37

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 :roll: )

Thanks in advance!

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Record owner change when selecting status field: Complete

Post by pbottcher » 2019-06-03 21:55

Hi ,

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'");
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
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.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Record owner change when selecting status field: Complete

Post by pbottcher » 2019-06-04 06:24

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.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Record owner change when selecting status field: Complete

Post by jsetzer » 2019-06-04 07:53

Open the file hooks/TABLENAME.php and modify the TABLENAME_before_update() function:

* 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;
}
Kind Regards,
Jan
Kind regards,
<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 readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply