Thanks John I got It working!
So for anyone following this post or in a similar boat here are the steps I followed:
Based on Johns response and the tutorial he posted I created a custom_utils.php file in my custom\include\ which according to the documentation is upgrade safe and added the following code
PHP Code:
<?php
function getAccountContacts($focus)
{
$query = "SELECT id, first_name,last_name FROM database.contacts where id in ( SELECT contact_id FROM database.accounts_contacts WHERE account_id = \"{$focus->id}\" )";
$result = $focus->db->query($query, false);
$list = array();
$list['']='';
while (($row = $focus->db->fetchByAssoc($result)) != null)
{
$list[$row['id']] = $row['first_name']." ".$row['last_name'];
}
return $list;
}
?>
I got a "$this not set to an object context error" so I had to change the $this in johns post to $focus(or the current bean) because the custom_utils.php must not be in a context where $this exists.
I then created a custom field called "accountcontact" in the Accounts module using the admin>studio and set its type to drop down, added it to the edit and detail view and saved and deployed the layouts.
then in my \custom\Extension\modules\Accounts\Ext\Vardefs\sug arfield_accountcontact_c.php I changed the $dictionary statement to:
PHP Code:
$dictionary['Account']['fields']['accountcontact_c']['function']='getAccountContacts';
I had to do a admin>quick rebuild and repair before my code was executing.
I am a total beginner at sugar development and PHP so please correct me if I have made any incorrect statements or assumptions.
Goodluck.
Bookmarks