<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi All,<div class=""><br class=""></div><div class="">Is there any way that vtiger can mass transfer records of child records if their father record changes owner?</div><div class=""><br class=""></div><div class="">Use case:</div><div class="">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.</div><div class=""><br class=""></div><div class="">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</div><div class=""><br class=""></div><div class=""><pre style="background-color: rgb(253, 255, 255); color: rgb(15, 15, 8); font-family: Menlo, monospace;" class="">$connectedEntities <span style="color: rgb(172, 5, 101);" class="">= </span>$adb<span style="color: rgb(172, 5, 101);" class="">-></span><span style="color: rgb(0, 209, 50);" class="">pquery</span>(<span style="color: rgb(117, 128, 0);" class="">"select sn.notesid as snote,<br class=""></span><span style="color: rgb(117, 128, 0);" class="">proc.</span><span style="color: rgb(35, 161, 176);" class="">processiid</span><span style="color: rgb(117, 128, 0);" class=""> as procid, proc.</span><span style="color: rgb(35, 161, 176);" class="">notesid</span><span style="color: rgb(117, 128, 0);" class=""> as procnote,<br class=""></span><span style="color: rgb(117, 128, 0);" class="">   pv.</span><span style="color: rgb(35, 161, 176);" class="">processiverificatiid</span><span style="color: rgb(117, 128, 0);" class=""> as pvid, pv.</span><span style="color: rgb(35, 161, 176);" class="">notesid</span><span style="color: rgb(117, 128, 0);" class=""> as pvnote,<br class=""></span><span style="color: rgb(117, 128, 0);" class="">   nc.</span><span style="color: rgb(35, 161, 176);" class="">nonconformitaid</span><span style="color: rgb(117, 128, 0);" class=""> as ncid, nc.</span><span style="color: rgb(35, 161, 176);" class="">notesid</span><span style="color: rgb(117, 128, 0);" class=""> as ncnote<br class=""></span><span style="color: rgb(117, 128, 0);" class="">   from vtiger_audit audit<br class=""></span><span style="color: rgb(117, 128, 0);" class="">   left join vtiger_senotesrel sn on audit.auditid = sn.crmid <br class=""></span><span style="color: rgb(117, 128, 0);" class="">   left join (select processiid, id_audit, notesid from vtiger_processi left join vtiger_senotesrel on crmid = processiid) proc on proc.</span><span style="color: rgb(35, 161, 176);" class="">id_audit</span><span style="color: rgb(117, 128, 0);" class=""> = audit.auditid<br class=""></span><span style="color: rgb(117, 128, 0);" class="">   left join (select processiverificatiid, audit_id, notesid from vtiger_processiverificati left join vtiger_senotesrel on crmid = processiverificatiid) pv on pv.</span><span style="color: rgb(35, 161, 176);" class="">audit_id</span><span style="color: rgb(117, 128, 0);" class=""> = audit.auditid<br class=""></span><span style="color: rgb(117, 128, 0);" class="">   left join (select nonconformitaid, nonconf_audit, notesid from vtiger_nonconformita left join vtiger_senotesrel on crmid = nonconformitaid) nc on nc.</span><span style="color: rgb(35, 161, 176);" class="">nonconf_audit</span><span style="color: rgb(117, 128, 0);" class=""> = audit.auditid<br class=""></span><span style="color: rgb(117, 128, 0);" class="">   where audit.auditid = </span><span style="color: rgb(169, 80, 0); font-style: italic;" class="">?</span><span style="color: rgb(117, 128, 0);" class="">"</span>, [$auditID]);<br class=""><br class="">   <span style="color: rgb(172, 5, 101);" class="">if</span>(<span style="color: rgb(172, 5, 101);" class="">!</span>$connectedEntities) <span style="color: rgb(172, 5, 101);" class="">return</span>;<br class=""><br class="">   <span style="color: rgb(122, 142, 204); font-style: italic;" class="">// transform the hashmaps received from the db into a string<br class=""></span><span style="color: rgb(122, 142, 204); font-style: italic;" class="">   </span>$entitiesToReassign <span style="color: rgb(172, 5, 101);" class="">= </span><span style="color: rgb(117, 128, 0);" class="">''</span>;<br class="">   $first <span style="color: rgb(172, 5, 101);" class="">= </span><span style="color: rgb(73, 20, 148);" class="">true</span>;<br class="">   <span style="color: rgb(172, 5, 101);" class="">while</span>($row <span style="color: rgb(172, 5, 101);" class="">= </span>$adb<span style="color: rgb(172, 5, 101);" class="">-></span><span style="color: rgb(0, 209, 50);" class="">fetchByAssoc</span>($connectedEntities)) {<br class="">       <span style="color: rgb(122, 142, 204); font-style: italic;" class="">// if this is the first loop cycle then there shouldn't be a comma<br class=""></span><span style="color: rgb(122, 142, 204); font-style: italic;" class="">       </span><span style="color: rgb(172, 5, 101);" class="">if</span>($first) {<br class="">           $first <span style="color: rgb(172, 5, 101);" class="">= </span><span style="color: rgb(73, 20, 148);" class="">false</span>;<br class="">       } <span style="color: rgb(172, 5, 101);" class="">else </span>{<br class="">           $entitiesToReassign <span style="color: rgb(172, 5, 101);" class="">.= </span><span style="color: rgb(117, 128, 0);" class="">','</span>;<br class="">       }<br class="">       <span style="color: rgb(122, 142, 204); font-style: italic;" class="">// concatenate the hashmap but first remove all the void values<br class=""></span><span style="color: rgb(122, 142, 204); font-style: italic;" class="">       </span>$entitiesToReassign <span style="color: rgb(172, 5, 101);" class="">.= </span><span style="color: rgb(0, 209, 50); font-style: italic;" class="">implode</span>(<span style="color: rgb(117, 128, 0);" class="">','</span>, <span style="color: rgb(0, 209, 50); font-style: italic;" class="">array_filter</span>(<span style="color: rgb(0, 209, 50); font-style: italic;" class="">array_values</span>($row), <span style="color: rgb(172, 5, 101);" class="">function </span>(<br class="">               <span style="color: rgb(169, 80, 0); font-style: italic;" class="">$element</span>) {<br class="">               <span style="color: rgb(172, 5, 101);" class="">return !empty</span>(<span style="color: rgb(169, 80, 0); font-style: italic;" class="">$element</span>);<br class="">           }));<br class="">   }<br class=""><br class="">   <span style="color: rgb(122, 142, 204); font-style: italic;" class="">// reassign<br class=""></span><span style="color: rgb(122, 142, 204); font-style: italic;" class="">   </span>$updateQuery <span style="color: rgb(172, 5, 101);" class="">= </span>$adb<span style="color: rgb(172, 5, 101);" class="">-></span><span style="color: rgb(0, 209, 50);" class="">pquery</span>(<span style="color: rgb(117, 128, 0);" class="">"UPDATE vtiger_crmentity set smownerid = </span><span style="color: rgb(169, 80, 0); font-style: italic;" class="">?</span><span style="color: rgb(117, 128, 0);" class=""> where crmid in (</span><span style="color: rgb(169, 80, 0); font-style: italic;" class="">?</span><span style="color: rgb(117, 128, 0);" class="">)"</span>, [<br class="">       <span style="color: rgb(0, 209, 50); font-style: italic;" class="">explode</span>(<span style="color: rgb(117, 128, 0);" class="">'x'</span>, $entityData[<span style="color: rgb(117, 128, 0);" class="">'assigned_user_id'</span>])[<span style="color: rgb(73, 20, 148);" class="">1</span>],<br class="">       $entitiesToReassign<br class="">   ]);</pre><div class=""><br class=""></div></div><div class="">Any idea?</div><div class=""><br class=""><div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div>Best Regards,<br class=""><b class="">Sukhdev Mohan</b> | <b class="">Software Developer</b><br class=""></div></div></div><br class="Apple-interchange-newline"></div><br class="Apple-interchange-newline"></div><br class="Apple-interchange-newline"></div><br class="Apple-interchange-newline"><br class="Apple-interchange-newline">
</div>

<br class=""></div></body></html>