Make a quick vote 🗳 ️How do you refer to SuiteCRM extensions: add-ons or plug-ins? Click here to have your say 👈

How to add a native field from a related module in the list view of another module

I want to add a native field (here: „name“) from another module (here: „accounts“) in the list view of another module (here: „bugs“). How am I supposed to do that?

I tried to achieve that in backend:

  1. Admin > Studio > Bugs > Fields > Add Field > Data Type „Relate“ and Module: „Accounts“
  2. Admin > Studio > Bugs > Layouts > List View > move new „accounts_xy“ field to „Default“ and save

Unfortunately this does not work, the new column stays empty.

I looked it up in the database table „accounts_bugs“, it contains the column „account_id“. So the reference to the „accounts“ table is there. I just don’t know how to populate the data on the list view of the bugs page.

Can anyone please point me in the right direction? Any help is highly appreciated. Thanks!

So there is already a many to many relationship Accounts<->Bugs by default. It appears as a subpanel on both the Account side and the Bugs Side. This is because a Bug can relate to many accounts and Accounts can have many Bugs. This IS NOT the field you created in studio.

If you want to relate a Bug to a single account, you can (like you did) create a relate field one to many on the bug side, this will show as a single field on the Bug side and a subpanel on the Account Side. However, you have to add the field in studio to edit view and detail view as well to be able to edit it on the Bug side. THEN if you populate that field I believe it will show on the list view as you have set it up. (If I understand correctly).

You can’t show many to many relationships in listview (I’m pretty sure?) because if there were 100 accounts related to the bug, you couldn’t display that in a line on the list view. That’s why there’s sub panels.

Hi Pstevens, thank you very much for your answer! I appreciate it. What you describe make sense and kind of works. But this approach has - as far as I can see so far - two downsides:

  1. In the bug subpanel of the detailed account page I am able to select any account name, not only the current one.
  2. SuiteCRM wont populate the account names in the already existing bugs.

Hmm…

Yes it won’t “sync” with the Bugs->Accounts relationship that’s already established. If you only have one account per bug, then what I suggested will work for you. Use the new relationship field instead of the default one.

However, if you want to use it as intended, you can’t see a many to many relationship field in list view. You might be better of (if you need this data) to create a report where you can show the data like this) and put it on your dashboard. The way it will look is if you have one bug that’s associated with two accounts is you’ll have two lined items for bugs, one for each account.

Good morning pstevens,

Thanks for your help. I now understand the problem and was able to implement the new relationship.

For the already existing relationships I wrote a small help script which writes the missing values into the database. This works perfectly. In case someone stumbles over the same or a similar problem - you’ll find the script below.

Only one problem remains
If I want to add a new bug in the bug-subpanel of the account viewpage, the field where I have to select the account appears now. BUT: Since the account is already clear, I want the field to be prefilled with the name of the account. This doesn’t sound difficult, but I just can’t get it to work. Can you maybe point me in the right direction?

if(!defined('sugarEntry')) define('sugarEntry', true);
require_once 'include/entryPoint.php';

echo "<pre>";

$countBugs = 0;
$countUpdates = 0;
$countDryRun = 0;

$bugBean = BeanFactory::getBean('Bugs');

$allBugs = $bugBean->get_full_list();

// Iterate through all bugs
foreach ($allBugs as $bug) {

	// only enter if the row is not updates yet!
	if (!$bug->account_id_c) {

		// if relationship is loaded
		if ($bug->load_relationship('accounts'))
		{
			$accounts = $bug->accounts->getBeans();

			foreach ($accounts as $account) {

				//$bug->account_id_c = $account_id;
				if ($_REQUEST['save']=='yes') {
					$bug->account_id_c = $account->id;
					$bug->save();
					echo "UPDATED - ";
					$countUpdates++;
				}
				else {
					echo "TEST RUN - ";
					$countDryRun++;
				}

				echo "Bug ID - " . $bug->id . "   Account ID: " . $account->id . "   Name: " . $account->name . "<br>";
				
			}
		}
	}
	$countBugs++;
}

echo "<br> Updates: " . $countUpdates;
echo "<br> Bugs: " . $countBugs;
echo "<br> Not updated: " . $countDryRun;
echo "<br>END";