Assign Record to Users automatically
Assign Record to Users automatically
Hi there gyus, is there a way to assign new records to users automatically when the admin inputs them?
Re: Assign Record to Users automatically
I have an idea how to do this, the senario is that we have a table (customers) with a lookup field with the name of the user (from table users), so in the users table that we have made we just put a field and put in the username of the user that we create in admin area. So if the admin puts in a new record in the table customers and chooses the user then automatically this will take the username from the users table and assign it to the right user. I dont know how to write the code for that, Please Help!
Re: Assign Record to Users automatically
So i have already proceed with that and what i did was that i created in appgini 2 tables, one named partners and one customers, in the table partners i puted a field username, then in customers, i have 2 fields, one is partner and its lookup field from table partners and has the name of the partner and the second is username that is also lookup from partners and autofill this field i choosed to be hide from table view and detail view also. Then in the hooks file in the customers.php i put this code after insert and after update
if($UserName){
$query = "UPDATE membership_userrecords SET memberID='$UserName' WHERE pkValue=$id AND tableName='customers'";
sql($query, $o);
}
That dosent seem to be working any suggetios?
if($UserName){
$query = "UPDATE membership_userrecords SET memberID='$UserName' WHERE pkValue=$id AND tableName='customers'";
sql($query, $o);
}
That dosent seem to be working any suggetios?
Re: Assign Record to Users automatically
Hi gatenet,
I think all you need is to set ownership of the new created record tho the chosen user, you can do this through adding a code like this in customers_after_insert hook in customers.php file:
you should also return false after setting the ownership, to prevent the
I think all you need is to set ownership of the new created record tho the chosen user, you can do this through adding a code like this in customers_after_insert hook in customers.php file:
Code: Select all
$today = time();
/* make the user is the owner of his customer record to */
sql("insert into membership_userrecords set tableName='customers',
pkValue='{$data['selectedID']}',
memberID='{$UserName}',
dateAdded='{$today}',
dateUpdated='{$today}',
groupID='{$ID_of_user's_group}'", $eo);
return FALSE;
-
- Posts: 28
- Joined: 2017-03-12 09:26
- Contact:
Re: Assign Record to Users automatically
Did somebody succeeded to change the owner of a record by using after_insert hook.
I tried to use this code and it is not working.
Based on a a drop down field, after update, i want to have the owner changed to the value of that drop down.
I tried to use this code and it is not working.
Based on a a drop down field, after update, i want to have the owner changed to the value of that drop down.
Best Regards,
Ionut Bocanet
Ionut Bocanet
Re: Assign Record to Users automatically
Hi,
try calling the built-in set_record_owner()-function instead and return FALSE afterwards. Otherwise AppGini will overwrite your ownership-definition by current user.
Hope this helps!
Regards,
Jan
try calling the built-in set_record_owner()-function instead and return FALSE afterwards. Otherwise AppGini will overwrite your ownership-definition by current user.
Code: Select all
set_record_owner("customers", $data["selectedID"], $UserName);
return FALSE;
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
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
-
- Posts: 28
- Joined: 2017-03-12 09:26
- Contact:
Re: Assign Record to Users automatically
worked like a charm. Thank you Jan
Best Regards,
Ionut Bocanet
Ionut Bocanet
Re: Assign Record to Users automatically
Great! Good to hear!
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
Re: Assign Record to Users automatically
I need to change ownership on insert as described above, but I cannot get the function to work. This is what I have.
assignments is the table, and UserName is based on an autofill from a selection on a dropdown.
What am I missing....
Thanks in advance
Jim
function assignments_after_insert($data, $memberInfo, &$args) {
set_record_owner("assignments", $data["selectedID"], $UserName);
return FALSE;
}
assignments is the table, and UserName is based on an autofill from a selection on a dropdown.
What am I missing....
Thanks in advance
Jim
function assignments_after_insert($data, $memberInfo, &$args) {
set_record_owner("assignments", $data["selectedID"], $UserName);
return FALSE;
}
Re: Assign Record to Users automatically
Hi,
what is the value of $UserName? It is not declared in the code you have posted.
Try this:
Best,
Jan
what is the value of $UserName? It is not declared in the code you have posted.
Try this:
Code: Select all
function assignments_after_insert($data, $memberInfo, &$args) {
set_record_owner('assignments', $data['selectedID'], $memberInfo['username']);
return FALSE;
}
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
Re: Assign Record to Users automatically
Thanks a lot Jan.
Still does not work....function assignments_after_insert($data, $memberInfo, &$args) {
set_record_owner('assignments', $data['selectedID'], $memberInfo['username']);
return FALSE;
}
Still does not work....function assignments_after_insert($data, $memberInfo, &$args) {
set_record_owner('assignments', $data['selectedID'], $memberInfo['username']);
return FALSE;
}
Re: Assign Record to Users automatically
Would the data type matter?
Re: Assign Record to Users automatically
Please give us a little more information:
Recommended next steps:
Regards,
Jan
What exactly does not work? Insert? ownership?Still does not work
Datatype of what?Would the data type matter?
Recommended next steps:
- Please ensure that $data['selectedID'] is populated correctly. I'm afraid there may be no selectedID array key.
To find out: Dump that variable for example using var_dump($_data['selectedID']); exit(); - Try with $data['YOUR_PRIMARY_KEY_COLUMN_NAME'], for example $data['id'] or $data['ID'] (according to you model)
- Check exact spelling (including letter case!) of your array keys
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
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
Re: Assign Record to Users automatically
Thanks for your help!!!
What exactly does not work? Insert? ownership? - The ownership does not change.
Datatype of what? UserName is of integer type as it is a lookup field would that matter?
Where would this code be placed? ump that variable for example using var_dump($_data['selectedID']); exit();
Tried this, $data['YOUR_PRIMARY_KEY_COLUMN_NAME'], for example $data['id'] or $data['ID'] (according to you model)
Check exact spelling (including letter case!) of your array keys
still no change in user name????
/**
* Called after executing the insert query (but before executing the ownership insert query).
*
* @param $data
* An associative array where the keys are field names and the values are the field data values that were inserted into the new record.
* For this table, the array items are:
* $data['ProjectId'], $data['Project_ID'], $data['Project_Manager'], $data['Project_Type'], $data['ProjectDuration'], $data['Task'], $data['ResourceId'], $data['Commitment'], $data['StartDate'], $data['EndDate'], $data['Writing'], $data['Total_Hours'], $data['UserName']
* Also includes the item $data['selectedID'] which stores the value of the primary key for the new record.
*
* @param $memberInfo
* An array containing logged member's info.
* @see https://bigprof.com/appgini/help/workin ... memberInfo
*
* @param $args
* An empty array that is passed by reference. It's currently not used but is reserved for future uses.
*
* @return
* A boolean TRUE to perform the ownership insert operation or FALSE to cancel it.
* Warning: if a FALSE is returned, the new record will have no ownership info.
*/
function assignments_after_insert($data, $memberInfo, &$args) {
set_record_owner('assignments', $data['Id'], $memberInfo['UserName']);
return FALSE;
}
/**
What exactly does not work? Insert? ownership? - The ownership does not change.
Datatype of what? UserName is of integer type as it is a lookup field would that matter?
Where would this code be placed? ump that variable for example using var_dump($_data['selectedID']); exit();
Tried this, $data['YOUR_PRIMARY_KEY_COLUMN_NAME'], for example $data['id'] or $data['ID'] (according to you model)
Check exact spelling (including letter case!) of your array keys
still no change in user name????
/**
* Called after executing the insert query (but before executing the ownership insert query).
*
* @param $data
* An associative array where the keys are field names and the values are the field data values that were inserted into the new record.
* For this table, the array items are:
* $data['ProjectId'], $data['Project_ID'], $data['Project_Manager'], $data['Project_Type'], $data['ProjectDuration'], $data['Task'], $data['ResourceId'], $data['Commitment'], $data['StartDate'], $data['EndDate'], $data['Writing'], $data['Total_Hours'], $data['UserName']
* Also includes the item $data['selectedID'] which stores the value of the primary key for the new record.
*
* @param $memberInfo
* An array containing logged member's info.
* @see https://bigprof.com/appgini/help/workin ... memberInfo
*
* @param $args
* An empty array that is passed by reference. It's currently not used but is reserved for future uses.
*
* @return
* A boolean TRUE to perform the ownership insert operation or FALSE to cancel it.
* Warning: if a FALSE is returned, the new record will have no ownership info.
*/
function assignments_after_insert($data, $memberInfo, &$args) {
set_record_owner('assignments', $data['Id'], $memberInfo['UserName']);
return FALSE;
}
/**
Re: Assign Record to Users automatically
Hi,
if I got you right, you have a column named "UserName" which is a lookup (to a different table).
You must not use a (non declared) variable $UserName (nor UserName as you have written).
I now assume this is a column of your model. You can get the value of that field from the $data array like this:
Attention:
array-key is case-sensitive! So please double check the spelling with capital "U" and capital "N".
Then you will have to fetch the memberID (which is as string) based on the seleted lookup-value (which is an integer) from your additional table like this:
As soon as you have $memberID (=string) you can pass it into set_record_owner function as last parameter.
Hope this helps. I'm sorry, I'm confused and don't know your model in details. Sorry if I cannot help you.
PS:
Ensure all users available in your dropdown have a matching "real" member in AppGini's membership_users table. Also, you will need a way to deny deleting or banning or un-approving users as long as they have tasks assigned to. Otherwise only admin will be able to re-assign them.
if I got you right, you have a column named "UserName" which is a lookup (to a different table).
You must not use a (non declared) variable $UserName (nor UserName as you have written).
I now assume this is a column of your model. You can get the value of that field from the $data array like this:
Code: Select all
$username_id = $data['UserName'];
array-key is case-sensitive! So please double check the spelling with capital "U" and capital "N".
Then you will have to fetch the memberID (which is as string) based on the seleted lookup-value (which is an integer) from your additional table like this:
Code: Select all
$memberID = sqlValue("SELECT `my_memberId_column_name` FROM `my_additional_table` WHERE `my_pk_column_name`='{$username_id}' LIMIT 1");
Hope this helps. I'm sorry, I'm confused and don't know your model in details. Sorry if I cannot help you.
PS:
Ensure all users available in your dropdown have a matching "real" member in AppGini's membership_users table. Also, you will need a way to deny deleting or banning or un-approving users as long as they have tasks assigned to. Otherwise only admin will be able to re-assign them.
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
Re: Assign Record to Users automatically
Thanks very much again..... I will work on this....
Where does all of the code you have provided go? After the function, but before the set record yes?
function assignments_after_insert($data, $memberInfo, &$args) {
HERE??
set_record_owner('assignments', $data['Id'], $memberInfo['UserName']);
return FALSE;
}
Where does all of the code you have provided go? After the function, but before the set record yes?
function assignments_after_insert($data, $memberInfo, &$args) {
HERE??
set_record_owner('assignments', $data['Id'], $memberInfo['UserName']);
return FALSE;
}
Re: Assign Record to Users automatically
I GOT it to work!!!
I'm shocked...
Thank you so much Jan!!
I'm shocked...
Thank you so much Jan!!
Re: Assign Record to Users automatically
Hi Jangle,
I am glad that the codes working good with your project.
As I am not good with codes, do you mind sharing with me the codes and where to place them as I am having the same problem and situation.
Thanking you in advance.
Zala.
I am glad that the codes working good with your project.
As I am not good with codes, do you mind sharing with me the codes and where to place them as I am having the same problem and situation.
Thanking you in advance.
Zala.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Re: Assign Record to Users automatically - Revisit
Hello, I had this working great in one of my applications. I am trying to add to a different applcation now and i get the error that the record cannot be inserted.
Anybody see anything wrong?
Thanks
Jim
Anybody see anything wrong?
Code: Select all
$username_id = $data['User'];
$emailname_id = $data['Email'];
$memberID = sqlValue("SELECT `User` FROM `Member_Information` WHERE `Id`='{$username_id}' LIMIT 1");
$emailname_id = sqlValue("SELECT `Email` FROM `Member_Information` WHERE `Id`='{$emailname_id}' LIMIT 1");
sendmail(array(
'to' => $emailname_id,
'name' => '',
'subject' => 'PHFR Overtime Report',
'message' => $mail_body
));
set_record_owner('Overtime_Submission', $data['Id'], $memberID);
return FALSE;
}
Jim
Re: Assign Record to Users automatically
Note, the email part works great.... if I use return true.
When I return false I get the error that the records cannot be inserted.
Thanks
Jim
When I return false I get the error that the records cannot be inserted.
Thanks
Jim
Re: Assign Record to Users automatically
Please disregard
I had placed the code in the before_insert function instead of the the after_insert.
Thanks
Jim
I had placed the code in the before_insert function instead of the the after_insert.
Thanks
Jim