<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://sugarclub.sugarcrm.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/210/how-do-you-autopopulate-a-related-field-in-custom-module-from-a-related-field-of-another-module</link><description>I&amp;#39;m fighting against this issue since a couple of weeks and I can&amp;#39;t figure out a way to do that. I have a custom module for the orders management and I need to produce invoices automatically. I&amp;#39;m following the example of &amp;#39;ConverToInvoice.php&amp;#39; from Quotes</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16636?ContentTypeID=1</link><pubDate>Mon, 22 Jun 2015 18:23:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:e6f096bd-8e5f-4974-a71c-2212f7053a01</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;span&gt;I am using it in v7.5.1.0 so it should work.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;Make sure you pass the module name, not the class and make the adjustment above to get back a list.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;FrancescaS&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16635?ContentTypeID=1</link><pubDate>Mon, 22 Jun 2015 08:33:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:bcc671c0-16e2-468a-848f-e5952a85048e</guid><dc:creator>sonesay inthavong</dc:creator><description>&lt;span&gt;Will this work for SuiteCRM 7.2 also? I&amp;#39;ve been trying with your method so far but its always returning false&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16637?ContentTypeID=1</link><pubDate>Tue, 30 Dec 2014 20:09:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:89ed3afb-8ee2-420a-98a8-f1342c22002a</guid><dc:creator>Kiddyty Kiddyty</dc:creator><description>&lt;span&gt;Hi , I have a similar situation but i dont quite understand what you have shared above. For my situation , I need to get the fields from Points_management -&amp;quot;balance_points&amp;quot; and set it as default for the field in Transaction so each transaction i will be able to calculate and update back the Points_management. I dont know how to retrieve and update back the related modules vice versa. I really need help as I am new to SugarCRM. Thank &amp;nbsp;you everyone.&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16634?ContentTypeID=1</link><pubDate>Mon, 15 Dec 2014 01:00:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:3ea3b1c6-85b0-4556-b689-2dab6a904993</guid><dc:creator>jlabuelo</dc:creator><description>&lt;span&gt;Thanks a lot for the answer!!!&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16633?ContentTypeID=1</link><pubDate>Fri, 12 Dec 2014 19:24:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:4755845f-afe5-4465-8cf1-679e9b3fa5a1</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;span&gt;Note that my function from the blog returns an array when it finds the relationship:&lt;/span&gt;&lt;br /&gt;&lt;span&gt;return(array($def['name'],&amp;nbsp;$m1)); &lt;/span&gt;&lt;br /&gt;&lt;span&gt;or&lt;/span&gt;&lt;br /&gt;&lt;span&gt;return(array($def['name'], $m2));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;The first element is the relationship name, the second the rhs module, just in case you need it. You get &amp;quot;Array&amp;quot; if you echo the result because it&amp;#39;s returning an array, if you try a var_dump instead you&amp;#39;ll see it&amp;#39;s components.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Try&lt;/span&gt;&lt;br /&gt;&lt;i&gt;list($rel_microchip, $m) =&amp;nbsp;getRelationshipByModulesgetRelacion(&amp;quot;R2_Solicitud&amp;quot;,&amp;quot;R2_Microchip&amp;quot;);&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;span&gt;HTH&lt;/span&gt;&lt;br /&gt;&lt;span&gt;FrancescaS&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16632?ContentTypeID=1</link><pubDate>Fri, 12 Dec 2014 18:37:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:13df7293-b6d2-415f-8a77-ca9b201c2d49</guid><dc:creator>jlabuelo</dc:creator><description>&lt;span&gt;Hi there&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I have &amp;nbsp;a similar problem like you are managing in this post. I have&amp;nbsp;created two custom modules with a one to one relationship&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;R2_Microchip has a one to one relathichip with R2_Solicitud. I am builing a button in the DetailView of the R2_Solicitud module and this button calls a controller function that needs to take the related R2_Microchip and work with it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;To do so i need to know the relationship between these two modules to be able to call it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I have found in this forum a post that points to &amp;nbsp;this blog&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://developer.sugarcrm.com/2013/05/29/programmatically-find-the-name-of-the-relationship-between-two-modules/" rel="nofollow" target="_blank"&gt;http://developer.sugarcrm.com/2013/05/29/programmatically-find-the-name-of-the-relationship-between-...&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;However in my code, when I call this function this way&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;$rel_microchip =&amp;nbsp;getRelationshipByModulesgetRelacion(&amp;quot;R2_Solicitud&amp;quot;,&amp;quot;R2_Microchip&amp;quot;);&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;$bean_solicitud-&amp;gt;load_relationship($rel_microchip);&lt;/i&gt;&lt;br /&gt;&lt;i&gt;$chip_bean=implode($bean_solicitud-&amp;gt;$rel_microchip-&amp;gt;get());&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I get this error message in the log file&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;i&gt;Warning&lt;/i&gt;&lt;/strong&gt;&lt;i&gt;: Illegal offset type in isset or empty in&amp;nbsp;&lt;/i&gt;&lt;strong&gt;&lt;i&gt;/opt/lampp/htdocs/sugarcrm/data/SugarBean.php&lt;/i&gt;&lt;/strong&gt;&lt;i&gt;&amp;nbsp;on line&amp;nbsp;&lt;/i&gt;&lt;strong&gt;&lt;i&gt;975&lt;/i&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;i&gt;Notice&lt;/i&gt;&lt;/strong&gt;&lt;i&gt;: Array to string conversion in&amp;nbsp;&lt;/i&gt;&lt;strong&gt;&lt;i&gt;/opt/lampp/htdocs/sugarcrm/custom/modules/R2_Solicitud/Funciones_Solicitud.php&lt;/i&gt;&lt;/strong&gt;&lt;i&gt;&amp;nbsp;on line&amp;nbsp;&lt;/i&gt;&lt;strong&gt;&lt;i&gt;75&lt;/i&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;i&gt;Notice&lt;/i&gt;&lt;/strong&gt;&lt;i&gt;: Undefined property: R2_Solicitud::$Array in&amp;nbsp;&lt;/i&gt;&lt;strong&gt;&lt;i&gt;/opt/lampp/htdocs/sugarcrm/custom/modules/R2_Solicitud/Funciones_Solicitud.php&lt;/i&gt;&lt;/strong&gt;&lt;i&gt;&amp;nbsp;on line&amp;nbsp;&lt;/i&gt;&lt;strong&gt;&lt;i&gt;75&lt;/i&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;i&gt;Fatal error&lt;/i&gt;&lt;/strong&gt;&lt;i&gt;: Call to a member function get() on a non-object in&amp;nbsp;&lt;/i&gt;&lt;strong&gt;&lt;i&gt;/opt/lampp/htdocs/sugarcrm/custom/modules/R2_Solicitud/Funciones_Solicitud.php&lt;/i&gt;&lt;/strong&gt;&lt;i&gt;&amp;nbsp;on line&amp;nbsp;&lt;/i&gt;&lt;strong&gt;&lt;i&gt;75&lt;/i&gt;&lt;br /&gt;&lt;/strong&gt;&lt;span&gt;(Line 75 is this one in my code&amp;nbsp;$chip_bean=implode($bean_solicitud-&amp;gt;$rel_microchip-&amp;gt;get());)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;As the function is returning just the word &amp;quot;Array&amp;quot;.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;If this function does not work.... How can I know how to call the relationships between two custom modules like&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;$bean_solicitud-&amp;gt;load_relationship($rel_microchip);??????&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Thanks a lot!!&lt;/span&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16631?ContentTypeID=1</link><pubDate>Fri, 27 Jun 2014 17:49:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:d5af3304-cf9f-4d33-8a1e-b8bd5a7b32c7</guid><dc:creator>luthien luthien</dc:creator><description>&lt;span&gt;Yes, perfect. It works! Thanks for all! &lt;/span&gt;&lt;br /&gt;&lt;span&gt;Cheers&lt;/span&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16630?ContentTypeID=1</link><pubDate>Fri, 27 Jun 2014 17:12:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:3a5ae926-bf72-4f60-afef-b00a77b1fbd0</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;span&gt;If you are creating a new invoice in the script then you can do so just populating the supplier id in the invoice bean populating the bean:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;//create a new bean&lt;br /&gt;$invoice=new AOS_Invoices();&lt;br /&gt;//for each object populate it&lt;br /&gt;$invoice-&amp;gt;field_name = &amp;quot;field_value&amp;quot;;&lt;br /&gt;//relate the invoice to the supplier&lt;br /&gt;$invoice-&amp;gt;supplier_id = $supplier_id //check the naming of the relate field&amp;#39;s id&lt;br /&gt;$invoice-&amp;gt;save();&lt;/pre&gt;&lt;br /&gt;&lt;span&gt;Francesca&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16629?ContentTypeID=1</link><pubDate>Fri, 27 Jun 2014 14:18:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:b8cb38c5-f511-49e4-97c3-7dbf7cc9e104</guid><dc:creator>luthien luthien</dc:creator><description>&lt;span&gt;Ok, perfect, I found the problem. My relationship was empty, I thought it was Many to Many, but the field value I was searching for was in a related field and the relationship was actually One To One. &lt;/span&gt;&lt;br /&gt;&lt;span&gt;Now I can retrieve all I need! :D&lt;/span&gt;&lt;br /&gt;&lt;span&gt;Last question. How do I fill related fields in my Invoice with values I just retrieved?&lt;/span&gt;&lt;br /&gt;&lt;span&gt;I have no problem on populate simple text fields, but is not the same for related fields.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Thank you, you are saving my life!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16628?ContentTypeID=1</link><pubDate>Thu, 26 Jun 2014 22:10:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:1bcabb62-4a73-4e9f-bc7e-31a1246d3425</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;span&gt;Try an echo after you get the relationship and die(); to see what you can see...&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;$order_to_account_relationship&amp;nbsp;= getRelationshipByModules (&amp;#39;Cproj_order_management01&amp;#39;, &amp;#39;Accounts&amp;#39;);&lt;br /&gt;echo(&amp;quot;relationship = &amp;quot; . $order_to_account_relationship);die();&lt;/pre&gt;&lt;br /&gt;&lt;span&gt;There may be a problem fetching the relationship....&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16627?ContentTypeID=1</link><pubDate>Thu, 26 Jun 2014 18:59:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:bb44572b-6310-4272-97a2-2559277b3c85</guid><dc:creator>luthien luthien</dc:creator><description>&lt;span&gt;Ok that&amp;#39;s a good news.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;I&amp;#39;m in troubles with &amp;#39;load_relationship()&amp;#39; function now..&lt;/span&gt;&lt;br /&gt;&lt;span&gt;As you told me, I called that function&amp;nbsp; on &lt;/span&gt;&lt;br /&gt;&lt;pre&gt;$bean-&amp;gt;load_relationship($order_to_account_relationship);&lt;/pre&gt;&lt;span&gt;but I receive a PHP Fatal Error: &lt;/span&gt;&lt;br /&gt;&lt;pre&gt;Call to a member function load_relationship() on a non-object in /../custom/modules/Cproj_order_management01/converToInvoice.php on line 95, referer: ..=Cproj_order_management01&amp;amp;action=DetailView&amp;amp;record=420d92b1-1cde-725b-b6ef-522725fbaf91&lt;/pre&gt;&lt;span&gt;I&amp;#39;m not understanding what&amp;#39;s the matter. I tried to declarate a new object for $bean but it didin&amp;#39;t solve the problem.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;This is the whole code I wrote since now.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;require_once(&amp;#39;modules/Cproj_order_management01/Cproj_order_management01.php&amp;#39;);&lt;br /&gt;require_once(&amp;#39;modules/AOS_Invoices/AOS_Invoices.php&amp;#39;);&lt;br /&gt;require_once(&amp;#39;modules/Accounts/Account.php&amp;#39;);&lt;br /&gt;require_once(&amp;#39;modules/a122_Suppliers/a122_Suppliers.php&amp;#39;);&lt;br /&gt;require_once(&amp;#39;modules/Relationships/Relationship.php&amp;#39;);&lt;br /&gt;&lt;br /&gt;global $timedate;&lt;br /&gt;&amp;nbsp;&amp;nbsp; //your function&lt;br /&gt;function getRelationshipByModules ($m1, $m2)&lt;br /&gt;{&lt;br /&gt;global $db,$dictionary,$beanList;&lt;br /&gt;$rel = new Relationship;&lt;br /&gt;if($rel_info = $rel-&amp;gt;retrieve_by_sides($m1, $m2, $db)){&lt;br /&gt;$bean = BeanFactory::getBean($m1);&lt;br /&gt;$rel_name = $rel_info['relationship_name'];&lt;br /&gt;foreach($bean-&amp;gt;field_defs as $field=&amp;gt;$def){&lt;br /&gt; if(isset($def['relationship']) &amp;amp;&amp;amp; $def['relationship']==$rel_name) {&lt;br /&gt;&amp;nbsp; return(array($def['name'], $m1));&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;} elseif($rel_info = $rel-&amp;gt;retrieve_by_sides($m2, $m1, $db)){&lt;br /&gt;$bean = BeanFactory::getBean($m2);&lt;br /&gt;$rel_name = $rel_info['relationship_name'];&lt;br /&gt;foreach($bean-&amp;gt;field_defs as $field=&amp;gt;$def){&lt;br /&gt; if(isset($def['relationship']) &amp;amp;&amp;amp; $def['relationship']==$rel_name) {&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(array($def['name'], $m2));&lt;br /&gt; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;return(FALSE);&lt;br /&gt;}&lt;br /&gt;$invoice=new AOS_Invoices();&lt;br /&gt;//$om=new Cproj_order_management01();&lt;br /&gt;&lt;br /&gt;$suppliers=array();&lt;br /&gt;&lt;br /&gt;$order_to_account_relationship = getRelationshipByModules (&amp;#39;Cproj_order_management01&amp;#39;, &amp;#39;Accounts&amp;#39;);&lt;br /&gt;$account_to_supplier_relationship = getRelationshipByModules(&amp;#39;Accounts&amp;#39;, &amp;#39;a122_Suppliers&amp;#39;);&lt;br /&gt;$bean-&amp;gt;load_relationship($order_to_account_relationship);&lt;br /&gt;foreach($bean-&amp;gt;$order_to_account_relationship-&amp;gt;getBeans() as $account){&lt;br /&gt;$account-&amp;gt;load_relationship($account_to_supplier_relationship);&lt;br /&gt;foreach($account-&amp;gt;$account_to_supplier_relationship-&amp;gt;getBeans() as $supplier){&lt;br /&gt;&amp;nbsp; &lt;br /&gt;if(!array_key_exists($supplier-&amp;gt;id, $suppliers))&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $suppliers[ $supplier-&amp;gt;id] = $supplier-&amp;gt;name;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;//when It works I&amp;#39;m gonna use that fields to fill my invoice fields&lt;br /&gt;&lt;strong&gt;[......]&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;$invoice-&amp;gt;save();&lt;br /&gt;&lt;br /&gt;ob_clean();&lt;br /&gt;header(&amp;#39;Location: index.php?module=AOS_Invoices&amp;amp;action=EditView&amp;amp;record=&amp;#39;.$invoice-&amp;gt;id);&lt;/pre&gt;&lt;span&gt;I&amp;#39;m going crazy. Thanks for your help, again.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16626?ContentTypeID=1</link><pubDate>Thu, 26 Jun 2014 16:56:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:86782eeb-19d9-4ca7-8afb-7dd5c55fbfd4</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;span&gt;That is the correct way to refer to custom fields, yes. They are part of the bean once retrieved.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;So $account-&amp;gt;field_name_c for custom fields is perfect.&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16625?ContentTypeID=1</link><pubDate>Thu, 26 Jun 2014 13:28:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:d5132faa-aa6d-4604-8fa0-808a5aa17df5</guid><dc:creator>luthien luthien</dc:creator><description>&lt;span&gt;Hi, thank you so much for your reply, it really helped me a lot.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;My relationships are One to Many and Many to Many, something like &lt;/span&gt;&lt;br /&gt;&lt;span&gt;Order Management &amp;lt;&amp;lt;---&amp;gt;&amp;gt; Account &amp;lt;&amp;lt;---&amp;gt; Supplier&lt;/span&gt;&lt;br /&gt;&lt;span&gt;so I guess I have to retrieve records using the second solution you told me.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;I can delete relationships and use only related fields, at the least for the One to Many relationships (I don&amp;#39;t actually need the &amp;#39;Many&amp;#39; part)..&lt;/span&gt;&lt;br /&gt;&lt;span&gt;I have just one question: almost all the fields I need to fill in Invoice, are custom. How can I refer those fields? They are columns of the _cstm tables on DB and I don&amp;#39;t know how to grab them.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;I was wondering if can I retrieve a record with &lt;/span&gt;&lt;br /&gt;&lt;pre&gt;$account-&amp;gt;retrieve($bean-&amp;gt;account_id);&lt;/pre&gt;&lt;span&gt;and refer a single fields as &lt;/span&gt;&lt;br /&gt;&lt;pre&gt;$account-&amp;gt;field_name;&lt;/pre&gt;&lt;span&gt;or &lt;/span&gt;&lt;br /&gt;&lt;pre&gt;$account-&amp;gt;field_name_c; //for a custom field&lt;/pre&gt;&lt;span&gt;Thank you so much for your support. &lt;/span&gt;&lt;br /&gt;&lt;span&gt;Cheers.&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How do you autopopulate a related field in custom module from a related field of another module?</title><link>https://sugarclub.sugarcrm.com/thread/16624?ContentTypeID=1</link><pubDate>Mon, 23 Jun 2014 18:55:00 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:d3e1c207-07b3-48ac-b457-3c02cc20c31b</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;span&gt;Cristina,&lt;/span&gt;&lt;br /&gt;&lt;span&gt;How many Accounts are related to your OrderManagement record and how many Suppliers are related to an Account? Are these records linked via a relate field or a relationship?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;If they are just relate fields the Account on the OrderManagement can be retrieved using the bean. If $bean is your Order Management bean, and account_id is the relate field for Account&amp;nbsp;on that bean.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;$account = new Account();&lt;br /&gt;$account-&amp;gt;retrieve($bean-&amp;gt;account_id);&lt;/pre&gt;&lt;br /&gt;&lt;span&gt;Now $account is the bean with all the Account information.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;In turn if Supplier is a relate field on Account and supplier_id is the relate field for Supplier on that bean:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;$supplier = new Supplier();&lt;br /&gt;$supplier-&amp;gt;retrieve($account-&amp;gt;supplier_id);&lt;/pre&gt;&lt;br /&gt;&lt;span&gt;If instead&amp;nbsp;you have multiple Accounts on an OrderManangement and/or multiple Suppliers on an Account and want to retrieve them all &amp;nbsp;you can get related beans using the relationship name as described by Jeff Bickart:&amp;nbsp;&lt;/span&gt;&lt;a href="http://developer.sugarcrm.com/2012/03/23/howto-using-the-bean-instead-of-sql-all-the-time/" rel="nofollow" target="_blank"&gt;http://developer.sugarcrm.com/2012/03/23/howto-using-the-bean-instead-of-sql-all-the-time/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;I always find getting the right relationship name a bit tricky so I created a function that given two modules returns the relationship name:&lt;/span&gt;&lt;br /&gt;&lt;a href="http://developer.sugarcrm.com/2013/05/29/programmatically-find-the-name-of-the-relationship-between-two-modules/" rel="nofollow" target="_blank"&gt;http://developer.sugarcrm.com/2013/05/29/programmatically-find-the-name-of-the-relationship-between-...&lt;/a&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;I personally keep this, and other such functions I created, in a utilities folder for reuse but you can also simply include it in the script you are writing.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;So you can do something like (note, I&amp;#39;m guessing your module names).&lt;/span&gt;&lt;br /&gt;&lt;span&gt;(assuming you have $bean = your current Order_Management bean)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;include_once(&amp;#39;&amp;lt;your path to my function&amp;gt;/getRelashionshipByModules.php&amp;#39;); $suppliers = array();&lt;br /&gt;$order_to_account_relationship =&amp;nbsp;getRelationshipByModules (&amp;#39;Order_Management&amp;#39;,&amp;nbsp;&amp;#39;Accounts&amp;#39;);&lt;br /&gt;$account_to_supplier_relationship = getRelationshipByModules(&amp;#39;Account&amp;#39;, &amp;#39;Suppliers&amp;#39;);&lt;br /&gt;$bean-&amp;gt;load_relationship($order_to_account_relationship);&lt;br /&gt;//loop through the Accounts linked to the Order&lt;br /&gt;foreach($bean-&amp;gt;$order_to_account_relationship-&amp;gt;getBeans() as $account){&lt;br /&gt;&amp;nbsp; &amp;nbsp; //loop through the suppliers for this account&lt;br /&gt;&amp;nbsp; &amp;nbsp; $account-&amp;gt;load_relationship($account_to_supplier_relationship);&lt;br /&gt;&amp;nbsp; &amp;nbsp; foreach($account-&amp;gt;$account_to_supplier_relationship-&amp;gt;getBeans as $supplier){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //check for duplicated by id (the key of the array)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //if you don&amp;#39;t already have this supplier in your list, add it.&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(!array_key_exists($supplier-&amp;gt;id, $suppliers)) $suppliers[ $supplier-&amp;gt;id] = $supplier-&amp;gt;name;&lt;br /&gt;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;}&lt;br /&gt;//the array $suppliers now contains all your suppliers with key the id of the record and value the name of the supplier.&lt;/pre&gt;&lt;br /&gt;&lt;span&gt;Note, the code above has not been tested, it&amp;#39;s just to give you some ideas.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;Spero che questa risposta ti sia d&amp;#39;aiuto.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;HTH&lt;/span&gt;&lt;br /&gt;&lt;span&gt;FrancescaS&lt;/span&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>