[Vtigercrm-developers] Updating Related Account Field Display Value Programmatically in Vtiger 7 Edit View
Emmanuele Maida
emmanuele.maida at gmail.com
Tue Apr 11 13:59:24 GMT 2023
Thanks for the reply, i would like for it to be in real time, and not after the record is saved.
Emmanuele Maida
Il Apr 10, 2023, 10:15 AM +0200, Sutharsan J <ajstharsan at gmail.com> ha scritto:
> Hi
>
> Why can't you use workflow update field option to auto fill account from parent account of selected contact?
>
> If you use reference field such as uitype 10 for contact and account it is possible
>
> Thanks
>
> > On Mon, 10 Apr 2023 at 03:10 Emmanuele Maida <emmanuele.maida at gmail.com> wrote:
> > > Hello everyone,
> > > 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.
> > > 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.
> > > Here's the relevant code from my Pratiche_Edit_Js file:
> > >
> > > updateAccountIdBasedOnContactId: function (container) {
> > > var thisInstance = this;
> > > container.find('input[name="contact_id"]').on(Vtiger_Edit_Js.referenceSelectionEvent, function (e, data) {
> > > console.log("Contact selected:", data);
> > >
> > > thisInstance.getRecordDetails(data).then(
> > > function (response) {
> > > console.log("Contact details:", response);
> > >
> > > var accountId = response['data']['account_id'];
> > > var contactName = data['selectedName'];
> > > var message = "Vuoi compilare i dati dell'azienda con quelli del contatto " + contactName + " appena selezionato?";
> > >
> > > app.helper.showConfirmationBox({ 'message': message }).then(function (e) {
> > > console.log("User confirmed");
> > >
> > >
> > > container.find('input[name="account_id"]').val(accountId).trigger(Vtiger_Edit_Js.referenceSelectionEvent, {
> > > 'source_module': 'Accounts',
> > > 'record': accountId
> > > });
> > >
> > > // Imposta il valore visualizzato del campo account
> > > container.find('input[name="account_id_display"]').val(response['data']['accountname']);
> > >
> > >
> > >
> > > // Ottieni i dettagli dell'azienda relazionata
> > > var accountData = {
> > > 'source_module': 'Accounts',
> > > 'record': accountId // Modifica qui
> > > };
> > >
> > > thisInstance.getRecordDetails(accountData).then(
> > > function (accountDetails) {
> > > console.log("Account details:", accountDetails);
> > >
> > > // Qui puoi utilizzare i dettagli dell'azienda per compilare altri campi
> > > // ad esempio: container.find('input[name="custom_field"]').val(accountDetails['data']['custom_field']);
> > >
> > > },
> > > function (accountError, accountErr) {
> > > console.log("Error retrieving account details:", accountError, accountErr);
> > > }
> > > );
> > >
> > > container.find('input[name="account_id_display"]').trigger('change');
> > > container.find('input[name="account_id"]').trigger('change');
> > >
> > > },
> > > function (error, err) {
> > > console.log("User canceled");
> > > });
> > > },
> > > function (error, err) {
> > > console.log("Error retrieving contact details:", error, err);
> > > }
> > > );
> > > });
> > > },
> > >
> > >
> > > 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.
> > > Could someone please provide some guidance on how to achieve this?
> > > Are there any specific events or methods that I should be using to update the display value of the related account field programmatically?
> > > Any help would be greatly appreciated. Thank you!
> > > _______________________________________________
> > > http://www.vtiger.com/
> --
> Development Manager
> Radus28 Software Solution
>
> 123, Level 2, Mc Larens Building
> Baudhaloka Mw.
> Colombo 04
> Sri Lanka
> M : +94773795291
> E : sutharsan at radus28.com
> W : www.radus28.com
> _______________________________________________
> http://www.vtiger.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20230411/b2093704/attachment-0001.html>
More information about the vtigercrm-developers
mailing list