[Vtigercrm-developers] Updating Related Account Field Display Value Programmatically in Vtiger 7 Edit View
Alan Lord
alanslists at gmail.com
Tue Apr 11 14:15:13 GMT 2023
As I recall, you will need to update the uimeta object in the dom
possibly via the SaveAjax action?
HTH
Al
On 09/04/2023 22:38, Emmanuele Maida 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/
More information about the vtigercrm-developers
mailing list