<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://sugarclub.sugarai.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 to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/dev-club/f/questions-answers/7085/how-to-add-a-related-field-without-adding-an-explicit-relationship</link><description>Hi Developer, 
 In SugarCRM Studio I can add a field with the type relate and link to the Accounts module. There should not be an explicit relationship between the modules. A custom table is then created for this, in which the ID of the account is inserted</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30835?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 17:53:09 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:21d28299-7648-4d00-b1ec-eb4e18fd1c81</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;p&gt;There are many things I would do differently now compared to what we did in the last decade.&amp;nbsp;I&amp;#39;m trying to clean some things, but it&amp;#39;s not easy to &amp;quot;back out&amp;quot; of older code/decisions, especially when there are multiple external integrations.&lt;/p&gt;
&lt;p&gt;Sadly, sometimes it&amp;#39;s easier to live with&amp;nbsp;those poor choices.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30834?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 17:38:47 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:f035ebbe-bd4f-42a4-849f-1a83e3ca3d97</guid><dc:creator>John Hawkins</dc:creator><description>&lt;p&gt;&lt;a class="internal-link view-user-profile" href="/members/francescas"&gt;Francesca Shiekh&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For fully custom modules (which sadly are not actually upgrade safe as there is nothing to stop Sugar using your module name in the future and having a clash apart from the prefix that is added by Module Builder!) I only ever use the vardefs.php and appropriate language files in the module directory for creating new fields. New fields in custom modules always go onto the main table.&lt;/p&gt;
&lt;p&gt;In fact, we generally have a team rule that we put updates to our own modules into the main directory. That applies to views and layouts as well. We tend to avoid using Studio for layout changes so don&amp;#39;t need to worry about the files going into the custom tree. That way we can use source control and CI tools to manage the files from afar. And we know when a customer has been fiddling with things &lt;span class="emoticon" data-url="https://sugarclub.sugarai.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;As you say, we all learn every day.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;JH.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30833?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 17:29:39 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:7ea861bc-ecbe-4865-b1a1-1a2823bd2825</guid><dc:creator>John Hawkins</dc:creator><description>&lt;p&gt;&lt;a class="internal-link view-user-profile" href="/members/tev"&gt;Tevfik T&amp;uuml;mer&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Your code example contains the line:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    &amp;#39;source&amp;#39; =&amp;gt; &amp;#39;custom_fields&amp;#39;,&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;which I believe will cause the resulting field to be created in the _cstm table which&amp;nbsp;&lt;a class="internal-link view-user-profile" href="/members/mneitzke"&gt;Martin Neitzke&lt;/a&gt;&amp;nbsp;was trying to avoid.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;JH.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30832?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 16:55:25 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:45f0bc75-05cf-4727-8ac6-59e0a0c4a2f9</guid><dc:creator>Tevfik T&amp;#252;mer</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="/members/mneitzke"&gt;Martin Neitzke&lt;/a&gt;&amp;nbsp;,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sorry if it didn&amp;#39;t fix right away. There could be many reasons for it. I noticed that you didn&amp;#39;t present source field.&lt;br /&gt;Following code block created the field sac_c in the Cases module on my local instance. You can give a try and validate. Please remember to add the sac_c field to the record view as well.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="php"&gt;&amp;lt;?php
$dictionary[&amp;#39;Case&amp;#39;][&amp;#39;fields&amp;#39;][&amp;#39;sac_c&amp;#39;] = array(
    &amp;#39;name&amp;#39; =&amp;gt; &amp;#39;sac_c&amp;#39;,
    &amp;#39;vname&amp;#39; =&amp;gt; &amp;#39;Contact&amp;#39;,
    &amp;#39;type&amp;#39; =&amp;gt; &amp;#39;relate&amp;#39;,
    &amp;#39;rname&amp;#39; =&amp;gt; &amp;#39;name&amp;#39;,
    &amp;#39;id_name&amp;#39; =&amp;gt; &amp;#39;id&amp;#39;,
    &amp;#39;module&amp;#39; =&amp;gt; &amp;#39;Contacts&amp;#39;,
    &amp;#39;table&amp;#39; =&amp;gt; &amp;#39;contacts&amp;#39;,
    &amp;#39;comment&amp;#39; =&amp;gt; &amp;#39;&amp;#39;,
    &amp;#39;required&amp;#39; =&amp;gt; false,
    &amp;#39;studio&amp;#39; =&amp;gt; true,
    &amp;#39;source&amp;#39; =&amp;gt; &amp;#39;custom_fields&amp;#39;,
);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note: Comparing to Harald&amp;#39;s example this definitions does not need link field definitions.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Tevfik T&amp;uuml;mer&lt;br /&gt;Sr. Developer Support Engineer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30831?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 16:51:08 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:7457a01c-c94f-4681-ab20-b840c0c74f8c</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;p&gt;Thank you for the explanation, that&amp;#39;s good to know.&lt;br /&gt;&lt;br /&gt;In the 12 years I&amp;#39;ve worked with Sugar I have always avoided creating new fields outside the _cstm table, but I agree, your solution is cleaner when it comes to joins etc. &lt;br /&gt;I particularly dislike Studio putting the fields in _cstm when&amp;nbsp;I have had to add fields to a module that is custom in the first place.&lt;/p&gt;
&lt;p&gt;There is always more to learn! :)&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30829?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 16:17:55 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:a4d32903-5e65-46ed-8098-cc14f86a445e</guid><dc:creator>John Hawkins</dc:creator><description>&lt;p&gt;&lt;a class="internal-link view-user-profile" href="/members/francescas"&gt;Francesca Shiekh&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Harald was pointing out the technique needed to get a field added to a core table rather than into a linked _cstm table as that is what&amp;nbsp;&lt;a class="internal-link view-user-profile" href="/members/mneitzke"&gt;Martin Neitzke&lt;/a&gt;&amp;nbsp;originally asked for help with.&lt;/p&gt;
&lt;p&gt;The only thing about this technique (as it uses the Extension framework) that is not upgrade safe is the potential that you are using a field name that Sugar may use in a future version. Harald&amp;#39;s solution to this is to use a unique prefix to avoid clashes. My preference is to use the _c suffix instead as that is guaranteed to be unique in a module as it is the suffix used for fields added via Studio - and hence into the _cstm table. To avoid confusing future devs who are looking at it and may expect _c fields to be in the _cstm table you could add a double suffix _core_c or even use two underscores, __c&lt;/p&gt;
&lt;p&gt;I have used the Extension technique since I first came to Sugar dev work (c. 2007 if you are asking!!) as I tend to prefer to avoid table joins where possible. As an oldie, I am still of the mindset to be as frugal with processing power as possible &lt;span class="emoticon" data-url="https://sugarclub.sugarai.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This is largely personal preference and the documented way of making upgrade-safe field additions is to use Studio or a package (or, if you want to do it manually, use an entry in to the fields_meta_data table so the field goes into _cstm) so you are not wrong. However, it is not really an issue to use the core table if you are careful.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;JH.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30828?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 15:33:59 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:3cfed66e-032a-4b03-8e3d-1f7e97d1f8db</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;p&gt;My point is that I believe anything custom (added by&amp;nbsp;us customers and not by Sugar) should go in the _cstm table not the core table for it to be upgrade safe.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30824?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 07:54:10 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:c8dab2af-2f46-43ad-80c1-abf20fa8e285</guid><dc:creator>Martin Neitzke</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/tev"&gt;Tevfik Tümer&lt;/a&gt;&amp;nbsp;,&lt;br /&gt;I tried your suggestion, but it did not bring about any changes. Thanks for your input though.&lt;br /&gt;Kind regards&lt;br /&gt;Martin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30823?ContentTypeID=1</link><pubDate>Fri, 23 Feb 2024 07:51:40 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:3a78c752-b607-4e60-8de2-eac7dbc3fe5c</guid><dc:creator>Martin Neitzke</dc:creator><description>&lt;p&gt;Thank you Harald,&lt;br /&gt;that was exactly what we needed and it seems to work very well. Thanks for the very detailed code snippet. This has clarified a lot about integrating related fields without relationships.&lt;/p&gt;
&lt;p&gt;&lt;a href="/members/francescas"&gt;Francesca Shiekh&lt;/a&gt;&amp;nbsp;: To add the account ID in the table, the Alter Table command is executed when repairing. That&amp;#39;s what we wanted: Add the new field to the core table so the value doesn&amp;#39;t show up in an extra custom table.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your support.&lt;/p&gt;
&lt;p&gt;Martin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30820?ContentTypeID=1</link><pubDate>Thu, 22 Feb 2024 19:00:09 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:3a5e9a1e-7ff9-48cb-a3ab-331b37efabea</guid><dc:creator>Francesca Shiekh</dc:creator><description>&lt;p&gt;Harald, if you add a relate field in Studio it would be added to the _cstm table, not the core table, right?&lt;/p&gt;
&lt;p&gt;The alter table statement here resulting from the vardef being added in code seems to suggest that it&amp;#39;s adding the custom field to the core table...&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Am I misunderstanding?&lt;/p&gt;
&lt;p&gt;thanks,&lt;br /&gt;FrancescaS&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30817?ContentTypeID=1</link><pubDate>Thu, 22 Feb 2024 12:43:26 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:a6697666-4344-4c95-9a09-1651992be4b4</guid><dc:creator>Tevfik T&amp;#252;mer</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/mneitzke"&gt;Martin Neitzke&lt;/a&gt;&amp;nbsp;,&lt;/p&gt;
&lt;p&gt;The relate fields are required to have a link to be used. However, if you provide the table that can be self sufficient as well.&amp;nbsp;&lt;br /&gt;So all you need to do please add:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    &amp;#39;table&amp;#39; =&amp;gt; &amp;#39;accounts&amp;#39;,&lt;/pre&gt;&lt;br /&gt;So your vardef should be:&lt;br /&gt;&lt;pre class="ui-code" data-mode="php"&gt;$dictionary[&amp;#39;PurchasedLineItem&amp;#39;][&amp;#39;fields&amp;#39;][&amp;#39;DIS&amp;#39;] = array(
    &amp;#39;name&amp;#39; =&amp;gt; &amp;#39;DIS&amp;#39;,
    &amp;#39;vname&amp;#39; =&amp;gt; &amp;#39;LBL_DIS&amp;#39;,
    &amp;#39;type&amp;#39; =&amp;gt; &amp;#39;relate&amp;#39;,
    &amp;#39;rname&amp;#39; =&amp;gt; &amp;#39;name&amp;#39;,
    &amp;#39;id_name&amp;#39; =&amp;gt; &amp;#39;id&amp;#39;,
    &amp;#39;module&amp;#39; =&amp;gt; &amp;#39;Accounts&amp;#39;,
    &amp;#39;table&amp;#39; =&amp;gt; &amp;#39;accounts&amp;#39;, // Table needs to be here
    &amp;#39;comment&amp;#39; =&amp;gt; &amp;#39;The name of the account represented by the account_id field&amp;#39;,
    &amp;#39;required&amp;#39; =&amp;gt; false,
    &amp;#39;studio&amp;#39; =&amp;gt; true,
);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps. :)&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Tevfik T&amp;uuml;mer&lt;br /&gt;Sr. Developer Support Engineer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add a related Field without adding an explicit relationship?</title><link>https://sugarclub.sugarai.com/thread/30816?ContentTypeID=1</link><pubDate>Thu, 22 Feb 2024 12:38:06 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:9de476eb-b8cc-4f6d-906c-4cf07246b935</guid><dc:creator>Harald Kuske</dc:creator><description>&lt;p&gt;To create a custom relation&amp;nbsp;field in the standard table you can use the extension framework by adding a name field and an id field to the table. Be sure that the name will never be part of the Sugar fields in the future, e.g. by a special prefix.&lt;/p&gt;
&lt;p&gt;As an example I added my_account_name/_id to the Notes modules:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="php"&gt;&amp;lt;?php 
 $dictionary[&amp;quot;Note&amp;quot;][&amp;quot;fields&amp;quot;][&amp;quot;my_account_name&amp;quot;] =
    array (
      &amp;#39;labelValue&amp;#39; =&amp;gt; &amp;#39;my_account_name&amp;#39;,
      &amp;#39;dependency&amp;#39; =&amp;gt; &amp;#39;&amp;#39;,
      &amp;#39;required_formula&amp;#39; =&amp;gt; &amp;#39;&amp;#39;,
      &amp;#39;readonly_formula&amp;#39; =&amp;gt; &amp;#39;&amp;#39;,
      &amp;#39;required&amp;#39; =&amp;gt; false,
      &amp;#39;readonly&amp;#39; =&amp;gt; false,
      &amp;#39;source&amp;#39; =&amp;gt; &amp;#39;non-db&amp;#39;,
      &amp;#39;name&amp;#39; =&amp;gt; &amp;#39;my_account_name&amp;#39;,
      &amp;#39;vname&amp;#39; =&amp;gt; &amp;#39;LBL_MY_ACCOUNT&amp;#39;,
      &amp;#39;type&amp;#39; =&amp;gt; &amp;#39;relate&amp;#39;,
      &amp;#39;massupdate&amp;#39; =&amp;gt; true,
      &amp;#39;hidemassupdate&amp;#39; =&amp;gt; false,
      &amp;#39;no_default&amp;#39; =&amp;gt; false,
      &amp;#39;comments&amp;#39; =&amp;gt; &amp;#39;&amp;#39;,
      &amp;#39;help&amp;#39; =&amp;gt; &amp;#39;&amp;#39;,
      &amp;#39;importable&amp;#39; =&amp;gt; &amp;#39;true&amp;#39;,
      &amp;#39;duplicate_merge&amp;#39; =&amp;gt; &amp;#39;enabled&amp;#39;,
      &amp;#39;duplicate_merge_dom_value&amp;#39; =&amp;gt; 1,
      &amp;#39;audited&amp;#39; =&amp;gt; true,
      &amp;#39;reportable&amp;#39; =&amp;gt; true,
      &amp;#39;unified_search&amp;#39; =&amp;gt; false,
      &amp;#39;merge_filter&amp;#39; =&amp;gt; &amp;#39;disabled&amp;#39;,
      &amp;#39;pii&amp;#39; =&amp;gt; false,
      &amp;#39;calculated&amp;#39; =&amp;gt; false,
      &amp;#39;len&amp;#39; =&amp;gt; 255,
      &amp;#39;size&amp;#39; =&amp;gt; &amp;#39;20&amp;#39;,
      &amp;#39;id_name&amp;#39; =&amp;gt; &amp;#39;my_account_id&amp;#39;,
      &amp;#39;ext2&amp;#39; =&amp;gt; &amp;#39;Accounts&amp;#39;,
      &amp;#39;module&amp;#39; =&amp;gt; &amp;#39;Accounts&amp;#39;,
      &amp;#39;rname&amp;#39; =&amp;gt; &amp;#39;name&amp;#39;,
      &amp;#39;quicksearch&amp;#39; =&amp;gt; &amp;#39;enabled&amp;#39;,
      &amp;#39;studio&amp;#39; =&amp;gt; &amp;#39;visible&amp;#39;,
    );
 $dictionary[&amp;quot;Note&amp;quot;][&amp;quot;fields&amp;quot;][&amp;quot;my_account_id&amp;quot;] =
    array (
      &amp;#39;required&amp;#39; =&amp;gt; false,
      &amp;#39;readonly&amp;#39; =&amp;gt; false,
      &amp;#39;name&amp;#39; =&amp;gt; &amp;#39;my_account_id&amp;#39;,
      &amp;#39;vname&amp;#39; =&amp;gt; &amp;#39;LBL_MY_ACCOUNT_ID&amp;#39;,
      &amp;#39;type&amp;#39; =&amp;gt; &amp;#39;id&amp;#39;,
      &amp;#39;massupdate&amp;#39; =&amp;gt; false,
      &amp;#39;hidemassupdate&amp;#39; =&amp;gt; false,
      &amp;#39;no_default&amp;#39; =&amp;gt; false,
      &amp;#39;comments&amp;#39; =&amp;gt; &amp;#39;&amp;#39;,
      &amp;#39;help&amp;#39; =&amp;gt; &amp;#39;&amp;#39;,
      &amp;#39;importable&amp;#39; =&amp;gt; &amp;#39;true&amp;#39;,
      &amp;#39;duplicate_merge&amp;#39; =&amp;gt; &amp;#39;enabled&amp;#39;,
      &amp;#39;duplicate_merge_dom_value&amp;#39; =&amp;gt; 1,
      &amp;#39;audited&amp;#39; =&amp;gt; false,
      &amp;#39;reportable&amp;#39; =&amp;gt; false,
      &amp;#39;unified_search&amp;#39; =&amp;gt; false,
      &amp;#39;merge_filter&amp;#39; =&amp;gt; &amp;#39;disabled&amp;#39;,
      &amp;#39;pii&amp;#39; =&amp;gt; false,
      &amp;#39;calculated&amp;#39; =&amp;gt; false,
      &amp;#39;len&amp;#39; =&amp;gt; 36,
      &amp;#39;size&amp;#39; =&amp;gt; &amp;#39;20&amp;#39;,
    );
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Add lables in the en_us language file for the two fields.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After Quick Repair &amp;amp; Rebuild i got the following DB correction script which had to be executed:&lt;/p&gt;
&lt;p&gt;/*COLUMNS*/&lt;br /&gt;/*MISSING IN DATABASE - my_account_id - ROW*/&lt;br /&gt;ALTER TABLE notes add COLUMN my_account_id char(36) NULL;&lt;/p&gt;
&lt;p&gt;DONE!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>