[Vtigercrm-developers] Mass transfer ownership of child module's records on father record owner change

Sukhdev Mohan s.mohan at myti.it
Fri Oct 16 12:31:50 GMT 2020


Hi All,

Is there any way that vtiger can mass transfer records of child records if their father record changes owner?

Use case:
I’ve One custom module to whom are connected 3 other modules (they are inter dependent) so If father changes owner so should the child. In addition all of these modules have documents attached, so even those needs to be transferred.

I figured that a custom function will do the trick, I’m trying to change the smownerid in DB but even if the update query is successful the values aren’t updated. follows my code

$connectedEntities = $adb->pquery("select sn.notesid as snote,
proc.processiid as procid, proc.notesid as procnote,
   pv.processiverificatiid as pvid, pv.notesid as pvnote,
   nc.nonconformitaid as ncid, nc.notesid as ncnote
   from vtiger_audit audit
   left join vtiger_senotesrel sn on audit.auditid = sn.crmid 
   left join (select processiid, id_audit, notesid from vtiger_processi left join vtiger_senotesrel on crmid = processiid) proc on proc.id_audit = audit.auditid
   left join (select processiverificatiid, audit_id, notesid from vtiger_processiverificati left join vtiger_senotesrel on crmid = processiverificatiid) pv on pv.audit_id = audit.auditid
   left join (select nonconformitaid, nonconf_audit, notesid from vtiger_nonconformita left join vtiger_senotesrel on crmid = nonconformitaid) nc on nc.nonconf_audit = audit.auditid
   where audit.auditid = ?", [$auditID]);

   if(!$connectedEntities) return;

   // transform the hashmaps received from the db into a string
   $entitiesToReassign = '';
   $first = true;
   while($row = $adb->fetchByAssoc($connectedEntities)) {
       // if this is the first loop cycle then there shouldn't be a comma
       if($first) {
           $first = false;
       } else {
           $entitiesToReassign .= ',';
       }
       // concatenate the hashmap but first remove all the void values
       $entitiesToReassign .= implode(',', array_filter(array_values($row), function (
               $element) {
               return !empty($element);
           }));
   }

   // reassign
   $updateQuery = $adb->pquery("UPDATE vtiger_crmentity set smownerid = ? where crmid in (?)", [
       explode('x', $entityData['assigned_user_id'])[1],
       $entitiesToReassign
   ]);

Any idea?

Best Regards,
Sukhdev Mohan | Software Developer






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20201016/e9d14fc8/attachment.html>


More information about the vtigercrm-developers mailing list