Skip to content

Instantly share code, notes, and snippets.

@nmusco
Forked from rajeshvaya/SugarCRM Cheat Sheet.md
Created August 17, 2017 17:30
Show Gist options
  • Save nmusco/a14b9c00689326361b2e7615d68115c2 to your computer and use it in GitHub Desktop.
Save nmusco/a14b9c00689326361b2e7615d68115c2 to your computer and use it in GitHub Desktop.
Joe_______'s SugarCRM Cheat Sheet

Sugarwiki

Adding a Field to the Modules Subpanel, Popup Search definitions

  • Code way:
1.      Use metadata/popupdefs.php (custom folder, if there is none copy original)
2.      Seek section searchdefs'   => array(…)
3.      Add field to searchdefs
  • Studio way:
Admin > Studio > Contacts > Layouts > PopupView > Popup Search
Subpanel Query Change with custom fields
1.      Open subpanel def
2.      Use ‘where’ clause
3.      Query mysql like “contacts.id in ( select id_c from contacts_cstm where contact_roles_c ='past' )”

If this fails, remember this:

  • Sugar will make a mess of your subquery. There’s an easy solution. Sugar handles query rewriting based on the strings “where” or “WHERE”. So, all you need to do is write your “WHERE” in mixed case, like so: "where" = "id in (select id from some_table WhErE field='xyz')"

Subpanel Query through code

Subpanel Change Top Buttons

1.      Edit the file custom/Extension/modules/<CustomModule>/Ext/Layoutdefs/<filename>
2.      Replace the top_button "SubPanelTopCreateButton" by "SubPanelTopButtonQuickCreate"(or your button)
3.      Go to Admin -> Repair -> Rebuild Extensions

SubPanel pass Data to quick create

ListView add own action

Create Custom Action

  • create a file in custom/modules/{MODULE}/ called "controller.php".
  • Here is an example of a custom controller.php
<?php
class CustomContactsController extends SugarController{
    public function action_MyActionName(){
        $record = $_REQUEST['record'];
        //do something with the record here
    }
}
  • In this function you have access to the entire SugarCRM API. You can create and update Sugar Beans, or run queries directly on the database, using the global "$db" object.

Custom Sugar View

Custom Sugar Ajax View

ListView add related Field

Custom Editview template

You would need to add a view.edit.php file in each module you want to use your template, overriding the preDisplay() method like so:

PHP Code:

function preDisplay()
{
    parent::preDisplay();
    $this->ev->tpl = 'yourtplfile.tpl';
}

Alternate Subpanel layout

  • Create subpanel LAyout File in modules/subpanels/metadata For instance "ForEvents";
  • Then go to module Layout definition:
  • /custom/Ext/Layoutdefs/layoutdefs.ext.php
  • Change Subpanel name to your PanelDefinitionfilename for instance "ForEvents"

Dynamic number of items in Subpanel

  • link
  • next if clause find -> $limit = $sugarconfig….records per page Replace with:
  • PHP Code:
if ($subpanel_def->_instance_properties['records_per_page']) {          
    $limit = $subpanel_def->_instance_properties['records_per_page'] + 0;          
} else {
    $limit   = $sugar_config['list_max_entries_per_subpanel'];
}

To override a module view class use

  • Custom<module>ViewEdit extends <module>ViewEdit

Log Objects

  • $GLOBALS['log']->error("handling contat= ". print_r($ListContact, true));

Subpanel Filter

Display SugarActionmenu as Buttons not as dropdown

  • admin > system settings > display actions within menus > uncheck

Dynamically Collapsing Subpanels Based on Record Values

Adding QuickSearch to a custom field

Creating a Custom Sugar Field

Enable / Disable subpanel create button depending on field value

http://forums.sugarcrm.com/f6/how-enable-disable-create-sub-panel-button-depending-field-value-68262/

Programmatically Find the Name of the Relationship between two Modules

Setting up memcache with Sugar on Windows

SugarCRM: Create a custom javascript validation before saving in Edit view

Use Sugarfields in Custom View

Display a Statusmessage using AJAXUI

// Display a message to the user before the action
ajaxStatus.showStatus('Message to display while doing the action');
ajaxStatus.hideStatus();
// Show Loadingscreen AJAXUI
SUGAR.ajaxUI.showLoadingPanel();
SUGAR.ajaxUI.hideLoadingPanel();

Prevent a Logic Hook From Running Multiple Times

Have a Subpanel QuickCreate refresh after the record is saved.

Admin Pages for Custom modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment