Assign record to other user

9 posts by 3 authors in: Forums > CMS Builder
Last Post: June 14, 2022   (RSS)

By andreasml - June 5, 2022


I use CSMB to record medical records. Various users have access to their personal data only by using their own username/password to login and by having "Author" privileges. Thus, each user logs in, inserts data of his/her patients and he/she is the only user that can have access (modify, delete etc) to these data.

I wonder whether it was possible to let a user, inserting data of a patient and assign them to another user. For example, I would like the user A to log in as Author, create a record and then assign this record to user B. From now on, this record would be seen only by user B and not user A. 

I suspect that a way to solve it could be if user A was able to change the "Created by" field on the top of each record, in this case to user B. Thus, this new patient's record would be visible (and editable) by the user B only. Unfortunately, this is not allowed to be done by a user who has access privileges as an "Author". I wonder whether it would be possible to leave this "Created by" field free to be changed by those who have "Author" privileges apart from those who have "Editor" privileges.

Of course I am free of any other way to get around this issue.

Kind regards and thank you for your great support.

Andreas Lazaris 

By pgplast - June 6, 2022

This can be done with a simple plugin.

First you include a user list in your section (e.g. 'new_owner') that pulls the nums and names of all your users from your accounts.

When the person creates a new section record, he selects from this list the person to whom he wishes the ownership re-assigned.

On save of the record, a 'post_save' plugin then captures the record number of the section record and the 'new_owner' value and updates the value of createByUseNum  (only if a value for 'new_owner' has been saved).

By andreasml - June 7, 2022


Thank you for your reply. 

On save of the record, a 'post_save' plugin then captures the record number of the section record and the 'new_owner' value and updates the value of createByUseNum  (only if a value for 'new_owner' has been saved).

How can I create this? Could you please give an example?



By pgplast - June 8, 2022


Create a field of list type in your section called (e.g.), ‘new_owner.’

Under ‘list’ type select ‘get options from MYSQL query’ from the list options

Put into the code field

SELECT num,CONCAT_WS(", ",last_name,first_name)
FROM `<?php echo $TABLE_PREFIX ?>accounts`
ORDER BY last_name


Create plugin called 'new_record_owner.php,'  a la:

Plugin Name: Reassign record ownership
Description: Plugin file: new_record_owner.php, table: 'your_section_name'
Version: #####
Requires at least: 3.0

addAction('record_postsave', 'new_record_owner', null, 2);

function new_record_owner($tableName,$recordNum) {

if($tableName!="new_owner") {

if (@$_REQUEST['new_owner']) {

$new_owner_num = $_REQUEST['new_owner'];
$record_num = $_REQUEST['num'];



$query = "UPDATE 'your_section_name' SET

createdByUserNum = '".$new_owner_num."',
updatedByUserNum = '".$new_owner_num."',

WHERE num = '".$record_num."'";
mysqli()->query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysqli()->error) . "\n");

}// end if

}// end function

upload and activate the plugin.

Create a dummy record in your section and select a new owner from the 'new_owner" list field and then check back to see if it now belongs to your newly selected owner.

Note that you have to put your section name in the appropriate areas above.

By andreasml - June 8, 2022


Many thanks for you kind answer. 

Unfortunately, I did not make it work.

Although, i insert the name of the owner (from the drop-down menu list), after saving the record, the owner and the updater of the record remain unchanged (there are still the original owners). I will have another look when I find some time and let you know for sure. Just a small clarification: if I need to have the same property to more than one sections what should I do? Just add the new section's name or something else? (see the following exam)


$query = "UPDATE infected_grafts, aortic_aneurysm_disease, carotid_disease SET


Kind regards, 


By andreasml - June 9, 2022


Thanks again!! It seems to work for me also (with some very mild modifications). I will let you know in more detail as long as I try it a bit more.

Kind regards,


By andreasml - June 10, 2022


It does work!! 

I wonder if there is a way to apply this to more than one sections, or you need to create a different plugin for every different section. 

Again, thanks for your assistance, 

Kind regards, 


By daniel - June 14, 2022

Hey Andreas,

Glad you were able to get this sorted out!

In regards to getting it working for different sections, the key is the "$tableName" variable and this portion of the code:

if($tableName!="test_update_owner") {

As it stands, this checks the current section and halts if it's not "test_update_owner" - it could be modified to permit multiple sections:

if($tableName!="test_update_owner" && $tableName != "other_permitted_table") {

It could also be updated to take different actions depending on the section with some moderate modifications:

if($tableName == "test_update_owner") {

 // run code here

} elseif ($tableName == "other_permitted_table") {

 // run alternate code here


Hope that helps!

Technical Lead