How to add a Standard module to My Activity Stream

SuiteCRM Version 7.11.15
I would like to include in My Activity Stream a message each time that any user create a New Quotte using the AOS_Quottation Module. I say that only is enabled for Contact Opportunities, cases or Leads.

I don’t know, but I did find a few things searching around the forums…

https://sugarclub.sugarcrm.com/explore/enterprise-professional/f/enterprise-professional-questions/3214/how-can-i-enable-activity-streams-for-custom-modules

Thanks for your quick answer. I have some additional question from your answers.
There is not logic hook created for aos_quote module. Is there any issue if I copy a logic hook from other and keep only the lines you describe?
I guess that once I create the php file I need to do a quick repair. Isn’t it?.
The customer module option does not what I am looking for because quotes is an standar module.
Is ay one able to tell me what option I neet to use for this module?

I’m afraid I never tried that code.

As general advice, I think it’s ok to add logic hooks in modules that don’t have them, and reusing code from other modules is a good way to start, although it needs to be checked in detail to see if everything applies in the new module, and to change whatever needs to be adapted.

Logic hooks do require a QR&R to be made active, although subsequent changes to the hook’s code probably won’t require anything, they should be immediately effective (unless some fancier caching is interfering).

Were you able to get it working? I just did this for our internal sales group today and can share the code if needed. They wanted to see “Accepted Quotes” but “Drafts” or another state is done the same way. Just let me know and I’ll post it.

@mcom I’d say it’s always useful to post code samples. If it doesn’t help now, it will help someone Googling around sometime in the future…

Here are the steps and the code in case it helps you or anyone else in the future. (Tested on version 7.10.29)

  1. Create or edit the file: ‘custom\modules\AOS_Quotes\logic_hooks.php’
<?php
// Do not store anything in this file that is not part of the array or the hook version.  This file will	
// be automatically rebuilt in the future. 
$hook_version = 1; 
$hook_array = Array(); 
// position, file, function 
$hook_array['before_save'] = Array(); 
$hook_array['before_save'][] = Array(1, 'AOS_Quotes push feed', 'custom/modules/AOS_Quotes/SugarFeeds/QuotesFeed.php','QuotesFeed', 'pushFeed'); 
$hook_array['after_ui_frame'] = Array(); 
$hook_array['after_save'] = Array(); 
$hook_array['after_relationship_add'] = Array(); 
$hook_array['after_relationship_delete'] = Array(); 
?>
  1. Create or edit the file: ‘custom\modules\SugarFeed\language\en_us.lang.php’
<?php
$mod_strings = array(
    'WON_QUOTE' => 'has an <b>ACCEPTED</b> quote',
);
  1. Create or edit the file: ‘custom\modules\AOS_Quotes\SugarFeeds\QuotesFeed.php’
<?php
if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}
/**
 *
 * SugarCRM Community Edition is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
 *
 * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
 * Copyright (C) 2011 - 2018 SalesAgility Ltd.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
 * reasonably feasible for technical reasons, the Appropriate Legal Notices must
 * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
 */

require_once('modules/SugarFeed/feedLogicBase.php');


class QuotesFeed extends FeedLogicBase
{
    public $module = "AOS_Quotes";
    public function pushFeed($bean, $event, $arguments)
    {
        $text = '';
        if (!empty($bean->fetched_row['stage']) && $bean->fetched_row['stage'] != $bean->stage && $bean->stage == 'Closed Accepted') {
            $currency = BeanFactory::newBean('Currencies');
            $currency->retrieve($bean->currency_id);
			
            //get account name for quote
			$account_bean = BeanFactory::getBean('Accounts', $bean->billing_account_id);
			
            $text = '{SugarFeed.WON_QUOTE} [' . $bean->module_dir . ':' . $bean->id . ':' . $bean->name . '] {SugarFeed.WITH} [Accounts:' . $bean->billing_account_id . ':' . $account_bean->name . '] {SugarFeed.FOR_AMOUNT} '. $currency->symbol . format_number($bean->total_amount);
        }
        
        if (!empty($text)) {
            SugarFeed::pushFeed2($text, $bean);
        }
    }
}
  1. Enable “Quotes” in the “Activity Stream Settings” in the Admin menu.

  2. Do a Quick Repair and Rebuild and you should see “Accepted Quotes” in the Stream. You can change or add other Quote states as desired following the same example. New Quotes seem to have a state of “Draft” but “Delivered” appears to be the correct state to trigger a “new quote” activity message. If you want “Delivered” you would just change step 2 to:

<?php
$mod_strings = array(
    'CREATED_QUOTE' => 'created a <b>NEW</b> quote',
);

and change step 3 to:

<?php
if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}
/**
 *
 * SugarCRM Community Edition is a customer relationship management program developed by
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
 *
 * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
 * Copyright (C) 2011 - 2018 SalesAgility Ltd.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
 * reasonably feasible for technical reasons, the Appropriate Legal Notices must
 * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
 */

require_once('modules/SugarFeed/feedLogicBase.php');


class QuotesFeed extends FeedLogicBase
{
    public $module = "AOS_Quotes";
    public function pushFeed($bean, $event, $arguments)
    {
        $text = '';
        if (!empty($bean->fetched_row['stage']) && $bean->fetched_row['stage'] != $bean->stage && $bean->stage == 'Delivered') {
            $currency = BeanFactory::newBean('Currencies');
            $currency->retrieve($bean->currency_id);
			
            //get account name for quote
			$account_bean = BeanFactory::getBean('Accounts', $bean->billing_account_id);
			
            $text = '{SugarFeed.CREATED_QUOTE} [' . $bean->module_dir . ':' . $bean->id . ':' . $bean->name . '] {SugarFeed.WITH} [Accounts:' . $bean->billing_account_id . ':' . $account_bean->name . '] {SugarFeed.FOR_AMOUNT} '. $currency->symbol . format_number($bean->total_amount);
        }
        
        if (!empty($text)) {
            SugarFeed::pushFeed2($text, $bean);
        }
    }
}

I think that’s all. Let me know if I forgot anything.

1 Like