Disable Assignment Notification On Module In SugarCRM

How can I disable assignment notifications for a particular custom module in SugarCRM?

Eg. When I create a new Case or Task and assign it to a User, the User receives an email about the assignment. If I turn off "Assignment Notifications" through Email Settings > Email Options in admin panel, it turns off all notifications. But in this case I want to turn off only Task Notifications and not Case or any other.

  • Hi Saiyed Faisal,

    We can achieve this by extending module bean and override the send_assignment_notifications function. Extending bean you can refer this community link :

    Sugar Bean Override Not Working 

    Hope it helps !

    Thank you.

  • Vignesh V mentioned extending the module's bean above. I made an example of how a developer might do this.

    Before considering applying any modifications to SugarBeans, I urge extreme caution. Altering existing logic in beans can have negative effects.

    I made the attached Module Loadable package that extends the Products(QLIs) module's bean to turn off assignment notifications for only this module. I achieved this by simply overriding the send_assignment_notifications method as an empty method that does nothing.

    This package contains the following to files:

    custom/modules/Products/Product.php

    <?php
    require_once('modules/Products/Product.php');
    class CustomProduct extends Product
    {
    function send_assignment_notifications($notify_user, $admin) {
    }
    }



    custom/Extension/application/Ext/Include/customProductBean.php

    <?php
    $objectList['Products'] = 'Product';
    $beanList['Products'] = 'CustomProduct';
    $beanFiles['CustomProduct'] = 'custom/modules/Products/Product.php';

    Note: Sorry for the multiple edits/alerts for this. Initially linked wrong package to response.

  • Hi Patrick,

    I have followed the same approach in SugarCRM Enterprise 7.9.2.0 in Leads module. It is working fine for me.

    Below is what i have done.

    Created a file in "custom/Extension/application/Ext/Include/Leads.php" and added below parameters

    <?php
    $objectList['Leads'] = 'Lead';
    $beanList['Leads'] = 'CustomLead';
    $beanFiles['CustomLead'] = 'custom/modules/Leads/Lead.php';

    Created "Lead.php" file in "custom/modules/Leads" and customized the assignment notification function to send notification to Lead only when "$this->lead_type_c == "Parent"

    <?php
    require_once("modules/Leads/Lead.php");
    class CustomLead extends Lead {
    public function __construct() {
    parent::__construct();
    }
    function send_assignment_notifications($notify_user, $admin)
    {
    if ( ($this->object_name == 'Lead') || (isset($notify_user->receive_notifications) && $notify_user->receive_notifications) ) {
    if($this->lead_type_c == "Parent")
    {
    $this->current_notify_user = $notify_user;

    $templateName = $this->getTemplateNameForNotificationEmail();
    $xtpl = $this->createNotificationEmailTemplate($templateName, $notify_user);
    $subject = $xtpl->text($templateName . "_Subject");
    $textBody = trim($xtpl->text($templateName));


    $mailTransmissionProtocol = "unknown";

    try {
    $mailer = $this->create_notification_email($notify_user);
    $mailTransmissionProtocol = $mailer->getMailTransmissionProtocol();

    // by default, use the following admin settings for the From email header
    $fromEmail = $admin->settings['notify_fromaddress'];
    $fromName = $admin->settings['notify_fromname'];

    if (!empty($admin->settings['notify_send_from_assigning_user'])) {
    // the "notify_send_from_assigning_user" admin setting is set
    // use the current user's email address and name for the From email header
    $usersEmail = $GLOBALS["current_user"]->emailAddress->getReplyToAddress($GLOBALS["current_user"]);
    $usersName = $GLOBALS["current_user"]->full_name;

    // only use it if a valid email address is returned for the current user
    if (!empty($usersEmail)) {
    $fromEmail = $usersEmail;
    $fromName = $usersName;
    }
    }

    // set the From and Reply-To email headers according to the values determined above (either default
    // or current user)
    $from = new EmailIdentity($fromEmail, $fromName);
    $mailer->setHeader(EmailHeaders::From, $from);
    $mailer->setHeader(EmailHeaders::ReplyTo, $from);

    // set the subject of the email
    $mailer->setSubject($subject);

    // set the body of the email... looks to be plain-text only
    $mailer->setTextBody($textBody);

    // add the recipient
    $recipientEmailAddress = $notify_user->emailAddress->getPrimaryAddress($notify_user);
    $recipientName = $notify_user->full_name;

    try {
    $mailer->addRecipientsTo(new EmailIdentity($recipientEmailAddress, $recipientName));
    } catch (MailerException $me) {
    $GLOBALS['log']->warn("Notifications: no e-mail address set for user {$notify_user->user_name}, cancelling send");
    }

    $mailer->send();
    $GLOBALS['log']->info("Notifications: e-mail successfully sent");
    } catch (MailerException $me) {
    $message = $me->getMessage();

    switch ($me->getCode()) {
    case MailerException::FailedToConnectToRemoteServer:
    $GLOBALS['log']->fatal("Notifications: error sending e-mail, smtp server was not found ");
    break;
    default:
    $GLOBALS['log']->fatal("Notifications: error sending e-mail (method: {$mailTransmissionProtocol}), (error: {$message})");
    break;
    }
    }
    }
    }
    }
    }

    Hope it helps..

  • Hello

    There is something equivalent to the php version of $bean->save(false); to avoid user email notificacion by API REST Calls?

    Or some variable flag on the json of rest/v10/Accounts POST?

  • Hi Patrick McQueen,

    What is file name where we will get default send_assignment_notifications function code?

  • Hi Patrick McQueen,

    Thank you for quick reply. I tried solution you have mentioned in this thread, but it is not working. I am trying to disable default assignment notification of a particular user. Do you know how to achieve it?

  • Hi Aakanksha,

    Disabling assignment notifications per user is a function in the user interface: a checkbox in their user profile. I assume you are trying to disable the notification for just one user in a particular module. That is next level beyond what I demonstrated above. Also, what I demonstrated above is neither supported nor recommended. It was just a proof of concept for those who felt risking the consequences were worth resolving the stated use case in this thread. I personally am not able to help you take this proof of concept to the next level. Perhaps another developer here is ready with some ideas.

  • Hello

    If you are in a logic hook or so, you need to send false on the save function like this. $bean->save(false); so the notification for the $bean module is not sent.

    Otherwize, you need to alter/custom the save function of the class module itself.

    I don't know if this still working on sugar version greather than 6.x but you can alter the file <sugar>/modules/<module>/Save.php as on "modules/Quotes/Save.php" and do the same as on $focus->save($check_notify); where $check_notify is false.

    Ultimatilly, you can custom the save function on the class directly like the one used on modules/Quotes/Quote.php at the function save() and do the same as on Save.php file:

    public function save($check_notify = false)
    {
    // CL Fix for 14365. Have a default quote_type value
    if (!isset($this->quote_type) || empty($this->quote_type)) {
    $this->quote_type = 'Quotes';
    }

    return parent::save($check_notify);
    }

    Now, when you determinate wich scenario works for you, you can add the logic that you need like check if the global $current_user has checked recieve system notifications or some other logic.

    Thanks