<div dir="ltr"><p style="margin:10px 0px;padding:0px;border:0px;outline:0px;font-size:14.3px;font-family:"lucida grande","Lucida Sans Unicode",tahoma,sans-serif;vertical-align:baseline;color:rgb(0,0,0)">Hello everyone,</p><p style="margin:10px 0px;padding:0px;border:0px;outline:0px;font-size:14.3px;font-family:"lucida grande","Lucida Sans Unicode",tahoma,sans-serif;vertical-align:baseline;color:rgb(0,0,0)">I'm currently working on customizing the Edit view of a custom module called "Pratiche" in Vtiger 7.5. The module has two related fields, contact_id and account_id. When a contact is selected, I want to automatically update the related account based on the selected contact's linked account.</p><p style="margin:10px 0px;padding:0px;border:0px;outline:0px;font-size:14.3px;font-family:"lucida grande","Lucida Sans Unicode",tahoma,sans-serif;vertical-align:baseline;color:rgb(0,0,0)">I have managed to update the account_id field value programmatically, but the display value of the related account field (account_id_display) does not update accordingly. The user has to refresh the page or to save to see the that the account has been correctly updated.</p><p style="margin:10px 0px;padding:0px;border:0px;outline:0px;font-size:14.3px;font-family:"lucida grande","Lucida Sans Unicode",tahoma,sans-serif;vertical-align:baseline;color:rgb(0,0,0)">Here's the relevant code from my Pratiche_Edit_Js file:<br><br></p><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Courier New",monospace;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(220,220,170)">updateAccountIdBasedOnContactId</span><span style="color:rgb(156,220,254)">:</span> <span style="color:rgb(86,156,214)">function</span> (<span style="color:rgb(156,220,254)">container</span>) {</div><div>        <span style="color:rgb(86,156,214)">var</span> <span style="color:rgb(156,220,254)">thisInstance</span> = <span style="color:rgb(86,156,214)">this</span>;</div><div>        <span style="color:rgb(156,220,254)">container</span>.<span style="color:rgb(220,220,170)">find</span>(<span style="color:rgb(206,145,120)">'input[name="contact_id"]'</span>).<span style="color:rgb(220,220,170)">on</span>(<span style="color:rgb(156,220,254)">Vtiger_Edit_Js</span>.<span style="color:rgb(156,220,254)">referenceSelectionEvent</span>, <span style="color:rgb(86,156,214)">function</span> (<span style="color:rgb(156,220,254)">e</span>, <span style="color:rgb(156,220,254)">data</span>) {</div><div>            <span style="color:rgb(156,220,254)">console</span>.<span style="color:rgb(220,220,170)">log</span>(<span style="color:rgb(206,145,120)">"Contact selected:"</span>, <span style="color:rgb(156,220,254)">data</span>);</div><div>    </div><div>            <span style="color:rgb(156,220,254)">thisInstance</span>.<span style="color:rgb(220,220,170)">getRecordDetails</span>(<span style="color:rgb(156,220,254)">data</span>).<span style="color:rgb(220,220,170)">then</span>(</div><div>                <span style="color:rgb(86,156,214)">function</span> (<span style="color:rgb(156,220,254)">response</span>) {</div><div>                    <span style="color:rgb(156,220,254)">console</span>.<span style="color:rgb(220,220,170)">log</span>(<span style="color:rgb(206,145,120)">"Contact details:"</span>, <span style="color:rgb(156,220,254)">response</span>);</div><div>    </div><div>                    <span style="color:rgb(86,156,214)">var</span> <span style="color:rgb(156,220,254)">accountId</span> = <span style="color:rgb(156,220,254)">response</span>[<span style="color:rgb(206,145,120)">'data'</span>][<span style="color:rgb(206,145,120)">'account_id'</span>];</div><div>                    <span style="color:rgb(86,156,214)">var</span> <span style="color:rgb(156,220,254)">contactName</span> = <span style="color:rgb(156,220,254)">data</span>[<span style="color:rgb(206,145,120)">'selectedName'</span>];</div><div>                    <span style="color:rgb(86,156,214)">var</span> <span style="color:rgb(156,220,254)">message</span> = <span style="color:rgb(206,145,120)">"Vuoi compilare i dati dell'azienda con quelli del contatto "</span> + <span style="color:rgb(156,220,254)">contactName</span> + <span style="color:rgb(206,145,120)">" appena selezionato?"</span>;</div><div>    </div><div>                    <span style="color:rgb(156,220,254)">app</span>.<span style="color:rgb(156,220,254)">helper</span>.<span style="color:rgb(220,220,170)">showConfirmationBox</span>({ <span style="color:rgb(206,145,120)">'message'</span><span style="color:rgb(156,220,254)">:</span> <span style="color:rgb(156,220,254)">message</span> }).<span style="color:rgb(220,220,170)">then</span>(<span style="color:rgb(86,156,214)">function</span> (<span style="color:rgb(156,220,254)">e</span>) {</div><div>                        <span style="color:rgb(156,220,254)">console</span>.<span style="color:rgb(220,220,170)">log</span>(<span style="color:rgb(206,145,120)">"User confirmed"</span>);</div><div>    </div><div>                        </div><div>                        <span style="color:rgb(156,220,254)">container</span>.<span style="color:rgb(220,220,170)">find</span>(<span style="color:rgb(206,145,120)">'input[name="account_id"]'</span>).<span style="color:rgb(220,220,170)">val</span>(<span style="color:rgb(156,220,254)">accountId</span>).<span style="color:rgb(220,220,170)">trigger</span>(<span style="color:rgb(156,220,254)">Vtiger_Edit_Js</span>.<span style="color:rgb(156,220,254)">referenceSelectionEvent</span>, {</div><div>                            <span style="color:rgb(206,145,120)">'source_module'</span><span style="color:rgb(156,220,254)">:</span> <span style="color:rgb(206,145,120)">'Accounts'</span>,</div><div>                            <span style="color:rgb(206,145,120)">'record'</span><span style="color:rgb(156,220,254)">:</span> <span style="color:rgb(156,220,254)">accountId</span></div><div>                        });</div><div>    </div><div>                        <span style="color:rgb(106,153,85)">// Imposta il valore visualizzato del campo account</span></div><div>                        <span style="color:rgb(156,220,254)">container</span>.<span style="color:rgb(220,220,170)">find</span>(<span style="color:rgb(206,145,120)">'input[name="account_id_display"]'</span>).<span style="color:rgb(220,220,170)">val</span>(<span style="color:rgb(156,220,254)">response</span>[<span style="color:rgb(206,145,120)">'data'</span>][<span style="color:rgb(206,145,120)">'accountname'</span>]);</div><div>                        </div><br><div>    </div><div>                        <span style="color:rgb(106,153,85)">// Ottieni i dettagli dell'azienda relazionata</span></div><div>                        <span style="color:rgb(86,156,214)">var</span> <span style="color:rgb(156,220,254)">accountData</span> = {</div><div>                            <span style="color:rgb(206,145,120)">'source_module'</span><span style="color:rgb(156,220,254)">:</span> <span style="color:rgb(206,145,120)">'Accounts'</span>,</div><div>                            <span style="color:rgb(206,145,120)">'record'</span><span style="color:rgb(156,220,254)">:</span> <span style="color:rgb(156,220,254)">accountId</span> <span style="color:rgb(106,153,85)">// Modifica qui</span></div><div>                        };</div><div>    </div><div>                        <span style="color:rgb(156,220,254)">thisInstance</span>.<span style="color:rgb(220,220,170)">getRecordDetails</span>(<span style="color:rgb(156,220,254)">accountData</span>).<span style="color:rgb(220,220,170)">then</span>(</div><div>                            <span style="color:rgb(86,156,214)">function</span> (<span style="color:rgb(156,220,254)">accountDetails</span>) {</div><div>                                <span style="color:rgb(156,220,254)">console</span>.<span style="color:rgb(220,220,170)">log</span>(<span style="color:rgb(206,145,120)">"Account details:"</span>, <span style="color:rgb(156,220,254)">accountDetails</span>);</div><div>    </div><div>                                <span style="color:rgb(106,153,85)">// Qui puoi utilizzare i dettagli dell'azienda per compilare altri campi</span></div><div>                                <span style="color:rgb(106,153,85)">// ad esempio: container.find('input[name="custom_field"]').val(accountDetails['data']['custom_field']);</span></div><div>    </div><div>                            },</div><div>                            <span style="color:rgb(86,156,214)">function</span> (<span style="color:rgb(156,220,254)">accountError</span>, <span style="color:rgb(156,220,254)">accountErr</span>) {</div><div>                                <span style="color:rgb(156,220,254)">console</span>.<span style="color:rgb(220,220,170)">log</span>(<span style="color:rgb(206,145,120)">"Error retrieving account details:"</span>, <span style="color:rgb(156,220,254)">accountError</span>, <span style="color:rgb(156,220,254)">accountErr</span>);</div><div>                            }</div><div>                        );</div><br><div>                        <span style="color:rgb(156,220,254)">container</span>.<span style="color:rgb(220,220,170)">find</span>(<span style="color:rgb(206,145,120)">'input[name="account_id_display"]'</span>).<span style="color:rgb(220,220,170)">trigger</span>(<span style="color:rgb(206,145,120)">'change'</span>);</div><div>                        <span style="color:rgb(156,220,254)">container</span>.<span style="color:rgb(220,220,170)">find</span>(<span style="color:rgb(206,145,120)">'input[name="account_id"]'</span>).<span style="color:rgb(220,220,170)">trigger</span>(<span style="color:rgb(206,145,120)">'change'</span>);</div><div>    </div><div>                    },</div><div>                        <span style="color:rgb(86,156,214)">function</span> (<span style="color:rgb(156,220,254)">error</span>, <span style="color:rgb(156,220,254)">err</span>) {</div><div>                            <span style="color:rgb(156,220,254)">console</span>.<span style="color:rgb(220,220,170)">log</span>(<span style="color:rgb(206,145,120)">"User canceled"</span>);</div><div>                        });</div><div>                },</div><div>                <span style="color:rgb(86,156,214)">function</span> (<span style="color:rgb(156,220,254)">error</span>, <span style="color:rgb(156,220,254)">err</span>) {</div><div>                    <span style="color:rgb(156,220,254)">console</span>.<span style="color:rgb(220,220,170)">log</span>(<span style="color:rgb(206,145,120)">"Error retrieving contact details:"</span>, <span style="color:rgb(156,220,254)">error</span>, <span style="color:rgb(156,220,254)">err</span>);</div><div>                }</div><div>            );</div><div>        });</div><div>    },</div></div><p style="margin:10px 0px;padding:0px;border:0px;outline:0px;font-size:14.3px;font-family:"lucida grande","Lucida Sans Unicode",tahoma,sans-serif;vertical-align:baseline;color:rgb(0,0,0)"><br><br><span style="font-size:14.3px">I have tried triggering the 'change' event on the account_id_display field, but it still doesn't update the display value. I am looking for a way to update the account display field in real-time so that the user can see the updated account name without refreshing the page.</span><br></p><p style="margin:10px 0px;padding:0px;border:0px;outline:0px;font-size:14.3px;font-family:"lucida grande","Lucida Sans Unicode",tahoma,sans-serif;vertical-align:baseline;color:rgb(0,0,0)">Could someone please provide some guidance on how to achieve this?<br>Are there any specific events or methods that I should be using to update the display value of the related account field programmatically?</p><p style="margin:10px 0px;padding:0px;border:0px;outline:0px;font-size:14.3px;font-family:"lucida grande","Lucida Sans Unicode",tahoma,sans-serif;vertical-align:baseline;color:rgb(0,0,0)">Any help would be greatly appreciated. Thank you!</p></div>