Page 1 of 1

Record owner change when selecting status field: Complete

Posted: 2019-06-03 18:37
by aarlauskas
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!

Re: Record owner change when selecting status field: Complete

Posted: 2019-06-03 21:55
by pbottcher
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

Re: Record owner change when selecting status field: Complete

Posted: 2019-06-04 06:24
by pbottcher
Just to add, bevor executing the sql query you need of course to check the result of your Drop-Down.

Re: Record owner change when selecting status field: Complete

Posted: 2019-06-04 07:53
by jsetzer
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