Auto Populate Related Fields For Account

As discussed Here, I tried to autopopulate related field.

Version: 7.11.21

Case Module I have addednew fields called

  • Account Associated with type Relate. [account_associated_c]
  • Account Description with type Text Area. [account_description_c]
  • Account Website with type URL. [accountwebsite_c]

Now I want to auto populate “Account Description” and “Account Website” based on selected “Account Associated” in editview.

so i have added follwing snippet into custom/modules/Cases/metadata/editviewdefs.php

array (
        'name' => 'account_associated_c',
        'studio' => 'visible',
        'label' => 'LBL_ACCOUNT_ASSOCIATED',
        'displayParams' => 
        array (
          'field_to_name_array' => 
          array (
            'id' => 'account_associated_id_c',
            'name' => 'account_associated_c',
            'website' => 'accountwebsite_c',
            'description' => 'account_description_c'
          ),
        ),
      ),

When i choose account nothing is getting reflected in UI.

please let me know if something is wrong.

Do a QR&R to see if changes take effect.

Thanks for the reply @BrozTechnologies !

I ran “Repair and Rebuild”.
Same thing. Once i select account from drop down nothing is getting populated.

Edit:
Was able to populate when selected using “Popup Selection”. is there Way to populate using Drop Down selection?

dropdown like this.

In addition to that. i tried auto populate field with type “Image”.
The texts are getting populated but not image.

is it really possible to populate image?

@pratik_p

Look at the posts for more information. I hope it’s help you.
https://community.suitecrm.com/t/automatic-field-filling/79063

1 Like

@p.konetskiy, thanks for replying.

According to thread, I don’t need extra search code to be written for quick search As i have to fill-in Account in Cases Edit View.

So I have added new file custom/modules/Cases/Ext/Vardefs/account_name.php with following content

<?php
$dictionary['Case']['fields']['account_name']['field_list']=array('account_name', 'account_id', 'accountwebsite_c', 'account_descrption_c');
$dictionary['Case']['fields']['account_name']['populate_list']=array('name', 'id', 'website', 'description');
?>

Ran Quick Repair and Rebuild.

But still the fields are not populating.

@pratik_p

You should use another directory. Look at the post attentive.

1 Like

@p.konetskiy, thanks! it worked fine!
But the Image type field is still not getting auto populated

@pratik_p

Sorry, I don’t understand you. What do you want to do with image?
For example, you can operate with link to a file.

@p.konetskiy I was able to populate “account website” and “account description” in to Cases, Those are fields with “Text” type.

let’s say i have have one field type “Image” in Account module with name “Account Image”.

Now once Account is selected I want that account’s Image to auto populate in Cases’s Custom Field “Account Image”.

i tried the same way but image is not getting populated

@pratik_p

You can generate link to file but you should write additional JavaScript for insert the link as a html object but not a text.

If i understand correctly,

The end goal is to show it on detail view.
We have two approaches,

  1. In Editview save it when account is selected, which will cause duplicate of file.
  2. Generate link using AccountID and pass it to Cases’s “Account Image” when we are doing get Case data.

I think second one if the right one to do.
Are you talking about same? if so, can you explain in detail where to add that logic. as i am new to suiteCRM.

@p.konetskiy
I was able to show Account Image as HTML in Cases using following solution.

  1. Create “Image” field with type Image in Acocunt.

  2. Create “Account Image” field with type HTML in Cases.

  3. add following code snippet in custom/modules/Cases/metadata/detailviewdefs.php

       array (
         'name' => 'account_image_c',
         'studio' => 'visible',
         'customCode' => '<img src="index.php?entryPoint=download&amp;id={$fields.account_id.value}_image_c&amp;type=Accounts" style="max-width: 600px;" height="">',
         'label' => 'LBL_ACCOUNT_IMAGE',
       ),
    

But i have issue in edit view. the Account Image field is not updating after selecting new account. it should pickup new Account ID, and recreate Image URL.

I have hard-coded file url pattern, it will break if there is slight change in future for upload URL. @p.konetskiy what do you think can we tweak it for the better approach if you have any in mind?

@pratik_p

I think that your customCode is normal. You take the image using id it’s right. I don’t think that it will break.
P.S. Sorry, I could not write before.