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: