Search code examples
vtigervtigercrm

How to add a combo drop-down user list in vtigercrm?


I'm using existing Task module under the Project module. I would like to assign particular task to multiple workers. Meaning that group of people will together complete the task.

I already have workers as users in my vtigercrm. So if i make a user selection multiple for assigning single task it could be easier to handle this use-case.

This use-case already have in Calendar module but i'm unable to understand how they implement.

I have a thorough knowledge on how to create custom user list drop-down in any module and i created lot more for my custom modules. Now stuck with the same scenario having multiple at a time. I tried like this in module.php, but it is not working.

$users = Vtiger_Module::getInstance('Users'); 
$module = Vtiger_Module::getInstance('MyModule'); 
$module->unsetRelatedList($users, 'Users', 'get_related_list'); 
$module->setRelatedList($users, 'Users', array('SELECT'), 'get_related_list'); 

Can anyone help me to get it done?


Solution

  • It is possible when you understood the Invite users field in Calender envent creation. Here the field must be multi-selection.

    Invite Users field

    You need to deal with vtiger_salesmanactivityrel table for inserting the multiple users and for showing in detail view.

    Here is the code to handle inviteusers.

    //Handling for invitees

    $selected_users_string =  $_REQUEST['inviteesid'];
                $invitees_array = explode(';',$selected_users_string);
                $this->insertIntoInviteeTable($module,$invitees_array);
    
    function insertIntoInviteeTable($module,$invitees_array)
        {
            global $log,$adb;
            $log->debug("Entering insertIntoInviteeTable(".$module.",".$invitees_array.") method ...");
            if($this->mode == 'edit'){
                $sql = "delete from vtiger_invitees where activityid=?";
                $adb->pquery($sql, array($this->id));
            }
            foreach($invitees_array as $inviteeid)
            {
                if($inviteeid != '')
                {
                    $query="insert into vtiger_invitees values(?,?)";
                    $adb->pquery($query, array($this->id, $inviteeid));
                }
            }
            $log->debug("Exiting insertIntoInviteeTable method ...");
    
        }
    

    Hope it would give you a better idea.