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
aarlauskas
Posts: 8
Joined: 2019-04-28 18:03

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!

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 628
Joined: 2018-04-01 10:12

Re: Record owner change when selecting status field: Complete

Post by pböttcher » 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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 628
Joined: 2018-04-01 10:12

Re: Record owner change when selecting status field: Complete

Post by pböttcher » 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.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 264
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

Post Reply