Skip to content

Instantly share code, notes, and snippets.

@elchele
elchele / customController.js
Created May 23, 2018 00:57
Invoking code on a successful response
myCustomJSMethod: function(module, guid){
//Instantiate a SugarBean object representing record identified by GUID
var beanObject = app.data.createBean(module, {id:guid});
//Send request to REST v10 API to retrieve the record
beanObject.fetch({
//Define the anonymous function that will execute on a successful response
success: function(data){ //the data parameter represents the JSON response from the API
//Do something with the response upon successful request
@elchele
elchele / CustomFilterAPI.php
Created February 2, 2018 19:37
Custom FilterAPI that hard codes an additional condition to the default "My Accounts" filter
<?php
/* File: ./custom/modules/Accounts/clients/base/api/CustomFilterApi.php */
require_once 'clients/base/api/FilterApi.php';
class CustomFilterApi extends FilterApi
{
public function registerApiRest()
{
@elchele
elchele / GetYTDValueExpression.php
Last active February 2, 2018 02:01
Custom Sugar Logic function for retrieving YTD value
<?php
/* File: ./custom/include/Expressions/Expression/String/GetYTDValueExpression.php */
require_once('include/Expressions/Expression/String/StringExpression.php');
class GetYTDValueExpression extends StringExpression
{
function evaluate() {
@elchele
elchele / hide_panel.ext.php
Created January 31, 2018 10:41
Custom dependency that hides/shows a given panel on RecordView if Sales Stage is set to Closed Lost on an Opportunity
<?php
/* File: ./custom/Extension/modules/Opportunities/Ext/Dependencies/hide_panel.ext.php */
$dependencies['Opportunities']['hide_panel'] = array(
'hooks' => array("edit"),
'trigger' => 'equal($sales_stage, "Closed Lost")',
'triggerFields' => array('sales_stage'),
'onload' => true,
'actions' => array(
@elchele
elchele / set_required.ext.php
Created January 31, 2018 09:30
Custom dependency to set a field as required based on another field's value
<?php
/* This example sets the Status Description field to required
if the Status field is set to 'Dead' within Leads module.
File: ./custom/Extension/modules/Leads/Ext/Dependencies/set_required.ext.php */
$dependencies['Leads']['req_status_desc_dep'] = array(
'hooks' => array("edit"),
'trigger' => 'true',
@elchele
elchele / idx_user_del_vis.ext.php
Created January 2, 2018 18:53
Vardefs extension for Tracker index -- for versions prior to 7.7.2
<?php
/* File: ./custom/Extension/modules/Trackers/Ext/Vardefs/idx_user_del_vis.ext.php */
$dictionary['Tracker']['indices'][] = array (
'name' => 'idx_tracker_userid_del_vis',
'type' => 'index',
'fields' =>
array (
0 => 'user_id',
@elchele
elchele / FakeLinkApi.php
Last active August 24, 2017 04:25
Customization for pulling external/ad-hoc data into a Sugar subpanel
<?php
/* File: ./custom/clients/base/api/FakeLinkApi.php */
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class FakeLinkApi extends SugarApi {
public function registerApiRest() {
return array(
'filterRelatedRecords' => array(
@elchele
elchele / subpanels.js
Last active May 16, 2017 21:22
Custom controller for subpanels layout, hides specific subpanels based on parent record data
({
/* Author: Angel Magaña -- cheleguanaco@cheleguanaco.com
* File: ./custom/modules/<Module>/clients/base/layouts/subpanels/subpanels.js
*
* Extended subpanels layout controller for hiding
* subpanels upon record load and based on parent record data
*
*/
extendsFrom: 'SubpanelsLayout',
@elchele
elchele / create.js
Created April 13, 2017 02:29
Refresh of a peer subpanel upon a change occurring in a different subpanel. Ex: Add record on Notes subpanel for Accounts => refresh Leads subpanel.
({
/* File: ./custom/modules/Notes/clients/base/views/create/create.js */
extendsFrom: 'CreateView',
save: function(){
this._super('save');
//TODO: Add logic to check if parent model exists to verify if being created via subpanel or other means.
@elchele
elchele / create.js
Created April 12, 2017 16:51
Example demonstrating changes to createview fields upon relate field changing
({
/* File: ./custom/modules/Contacts/clients/base/views/create/create.js */
extendsFrom:'CreateView',
initialize: function(options){
this._super('initialize', [options]);
this.model.on('change:account_id', this.test, this);