sugar u: session 7: an introduction to sugar development, going way beyond studio
DESCRIPTION
TRANSCRIPT
An Introduction to Sugar Development,Going Way Beyond Studio
Sugar U.
Tweet: #SCON12
Profile
NEPO Systems:Founded 2008SugarCRM Partner since 2008 (current Gold Partner)Customers Worldwide / Public & Private SectorPremium Sugar Support & Sugar Apps
Jeff BickartCTO – NEPO Systems SugarCRM developer since 2005 (v4.0.0a)Where everybody knows your name
Apple Inc, Sun Microsystem
04/09/2023 ©2012 SugarCRM Inc. All rights reserved. 3
Tweet: #SCON12
Going Beyond Studio
04/09/2023 ©2012 SugarCRM Inc. All rights reserved. 4
Where is everything kept?Directories of interest
customcachedatamodulesinclude
Where do my changes belong?custom, custom, custom
SugarBeans LogicHooks SugarFields
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 5
SugarBeansdata/SugarBean.php
SugarBean is a component, that represents persistent data maintained in a database
Typesbasic, company, file, issue, person, sale
ExamplesAccounts, Documents, Cases, Contacts, Opportunities
Basic SugarBeanAll Beans extend basic which provides the fields:id, name, date_entered, date_modified, modified_user_id, created_by, description, deleted
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 6
SugarBeanTips & Tricks
How to get data from the databaseretrieve, get_list, get_detail, get_full_list, retrieve_by_string_fields
Obtain a Bean by IDBefore 6.4
$account = new Account();$account->retrieve($id);
6.4$account = BeanFactory::getBean(‘Accounts’, $id);
Obtain a set of Beans with filter$account = new Account();$account->retrieve_by_string_fields(array(‘name’ => ‘SugarCRM’, ‘assigned_user_id’ => ‘1’)
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 7
SugarBeanRelationships
$account = BeanFactory::getBean($id); Get All Related Objects
$account->load_relationship(‘contacts’);Before 6.4
$contactList = $accounts->contacts->getBeans(new Contact());
6.4$contactList = $accounts->contacts->getBeans();
Get subset of Related Objects$contactList = $accounts->get_linked_beans(‘contacts’, ‘Contact’, array(‘date_entered’), 0, 5);
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 8
LogicHooks
Allow you to add functionality to certain actions, such as before saving a bean, in an upgrade-safe manner.
Module hooksbefore_delete - Fired before a record is deletedafter_delete - Fired after a record is deletedbefore_restore - Fired before a record is undeletedafter_restore - Fired after a record is undeletedafter_retrieve - Fired after a record has been retrieved from the databasebefore_save - Fired before a record is savedafter_save - Fired after a record is savedprocess_record - Fired immediately prior to the database query resulting in a record being made current
Other Types of LogicHooksUsers module
before_logout, after_logout, after_login, after_logout, before_logout, login_failed
Application hooksafter_ui_frame, after_ui_footer, server_round_trip
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 9
LogicHook Examplecustom/modules/Accounts/logic_hooks.php$hook_version = 1; $hook_array = Array(); $hook_array['before_save'] = Array(); $hook_array['before_save'][] =
Array( 100, 'Reassign All Related Records', 'custom/modules/Accounts/ReassignHandler.php','ReassignHandler', 'reassignRecords');
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 10
Reassign All Related Recordsbefore_save LogicHook
$user = new User();$user->disable_row_level_security = true;$user->retrieve($bean->assigned_user_id);foreach ($bean->field_defs as $field => $info) { if ($info['type'] == 'link') { switch ($field) { default: $bean->load_relationship($field);
foreach ($bean->$field->getBeans(new $info['bean_name']) as $focus) {
if ($focus->id != "") { $focus->assigned_user_id = $bean->assigned_user_id; $focus->team_set_id = $user->team_set_id; $focus->team_id = $user->default_team;
/* DO NOT SAVE THE EMAIL ADDRESSES */ $focus->in_workflow = true; $focus->save(false); }
} } }}
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 11
SugarFields
Custom Display of items on Screens Code goes into
custom/include/SugarFields/Fieldscustom/include/SugarFields/Fields/Contact/:
– DetailView.tpl EditView.tpl SearchView.tpl SugarFieldContact.php WirelessEditView.tpl
ExamplesOverride Existing Fields
– Phone Formatting– Address– Images (Gravatar) sugarforge.org/projects/gravatar/
Custom Fields– Contact
Update the custom/modules/<Module>/metadata– detailviewdefs.php, editviewdefs.php, etc…
▪ 'name' => ’<field name>',▪ 'type' => 'contact’,
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 12
SugarFieldsExamples
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 13
SugarFieldsExamples
DetailView
EditView
Tweet: #SCON12
Appendix
Directory Structure
04/09/2023 ©2012 SugarCRM Inc. All rights reserved. 14
Tweet: #SCON1204/09/2023 ©2012 SugarCRM Inc. All rights reserved. 15
SugarBeanToggles
$disable_row_level_security $update_date_modified $update_modified_by $update_date_entered
04/09/2023 ©2012 SugarCRM Inc. All rights reserved. 16
Submit Session Feedback
Select the SugarCon Mobile App: 1) Tap on this session2) Tap on survey3) Submit your feedback
*Prizes for attendees who submit session feedback using the Mobile App
04/09/2023 ©2012 SugarCRM Inc. All rights reserved. 17
#SCON12