alerts not working

Hi,

I installed a new version of suitecrm 7.3.2max. and also 7.6.4 but in both the versions, Alerts are not workingā€¦
I tried enabling desktop notifications from admin but it didnā€™t workā€¦
Tried a few changes in the code as wellā€¦ But no luckā€¦
I am sending the code which I saved in the (instancename)/custom/modules/accounts/accounts.php
Code:

<?php $alert = BeanFactory::newBean('Alerts'); $alert->name = 'My Alert'; $alert->description = 'This is my alert!'; $alert->url_redirect = 'index.php'; $alert->target_module = 'Accounts'; $alert->assigned_user_id = '1'; $alert->type = 'info'; $alert->is_read = 0; $alert->save(); Please reply asap.. Thank You.. :)

Hi Guysā€¦

I found the solution for creating alertsā€¦

Here is are the steps:

Creating a Logic Hook using the Extension Framework
./custom/Extension/modules//Ext/LogicHooks/.php

<?php $hook_array['after_save'][] = Array( //Processing index. For sorting the array. 1, //Label. A string value to identify the hook. 'after_save example', //The PHP file where your class is located. 'custom/modules//after_save_class.php', //The class the method is in. 'after_save_class', //The method to call. 'after_save_method' ); ?>

./custom/modules//after_save_class.php

<?php if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); class after_save_class { function after_save_method($bean, $event, $arguments) { $alert = BeanFactory::newBean('Alerts'); $alert->name = 'My Alert'; $alert->description = 'This is my alert!'; $alert->url_redirect = 'index.php'; $alert->target_module = 'Accounts'; $alert->assigned_user_id = '1'; $alert->type = 'info'; $alert->is_read = 0; $alert->save(); } } ?>

We created for accounts moduleā€¦ similarly we can create for all modulesā€¦

Only one thing that we are stuck isā€¦ in the above code ā€¦
$alert->assigned_user_id = ā€˜1ā€™;

by the above line of code, this alert can be created only for one user at a time whose ID we put in the assigned user placeā€¦
So can anyone suggest how can we create it for all users irrespective of the users ā€¦

Thank Youā€¦

1 Like

Hi Maybe so


$o = BeanFactory::getBean('Users');
$users = BeanFactory::getBean('Users')->get_list('users.id','users->status="active"'); 

foreach($users as $user)
{
    // create alert;
   $alert->assigned_user_id = $user->id;
   $alerst->save();
}

Thank you for the replyā€¦

But I am not able to figure out where I am suppose to put the above codeā€¦

I tried putting this code but I am getting database failureā€¦
so can please guide me as to where to put the above code?

Thank you once again.

If your code work without error :
But check the php error. I have not controlled syntax



class after_save_class
{
function after_save_method($bean, $event, $arguments)
{
$alert = BeanFactory::newBean('Alerts');
$alert->name = 'My Alert';
$alert->description = 'This is my alert!';
$alert->url_redirect = 'index.php';
$alert->target_module = 'Accounts';

$alert->type = 'info';
$alert->is_read = 0;

$users = BeanFactory::getBean('Users')->get_list('users.id','users->status="active"'); 

foreach($users as $user)
{

$alert->assigned_user_id = $user->id;
$alert->save();
}


}
}

it is giving database failureā€¦ can anyone helpā€¦

Give suitecrm log !

Thank You for your quick reply

This is what I get in suitecrm logā€¦

06/06/16 11:25:41 [5484][1][FATAL] Error running count query for User List: Query Failed: SELECT count(*) c FROM users LEFT JOIN users jt2 ON users.reports_to_id=jt2.id AND jt2.deleted=0

AND jt2.deleted=0 where (users->status=ā€œactiveā€) AND users.deleted=0: MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ā€˜>status=ā€œactiveā€) AND users.deleted=0ā€™ at line 3
06/06/16 11:34:57 [5484][1][FATAL] Error running count query for User List: Query Failed: SELECT count(*) c FROM users LEFT JOIN users jt2 ON users.reports_to_id=jt2.id AND jt2.deleted=0

AND jt2.deleted=0 where (users->status=ā€œactiveā€) AND users.deleted=0: MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ā€˜>status=ā€œactiveā€) AND users.deleted=0ā€™ at line 3

Yesā€¦

itā€™s users.status=ā€œActiveā€
and not users->status
:wink:

Its not working and now I am not getting errors also in my log file.

:frowning: :ā€™(

I tried doing all possible changes but not able to get the desired output ā€¦

Please can someone suggest ā€¦ this is driving me crazyyyā€¦

Look here http://alanstorm.com/sugarcrm_model_bean
You have the respond ā€¦ read this page and find the error. This is a lessons for learn.
After come back and give the solution.

Guys it is working and we got the solution.

we do not require to do any changes in the codeā€¦ it will give alerts to the users to whom the particular account, lead, etc will be assigned toā€¦

Thank You for your support and helpā€¦ :slight_smile: