View source | Discuss this page | Page history | Printable version   

ERP 2.50:Developers Guide/How to develop an alert/it

Contents

Obiettivo

The objective of this how-to is to illustrate how you can add new alerts to Openbravo. Alerts are non-intrusive informational messages to individual users or groups (roles) about anything within the system. One can define unlimited number of alerts for various statuses, errors, informative purposes, reminder etc. Some examples are:

and many more.

Definire un avviso

First of all, the condition under which the alert appears needs to be defined. This is done using a SQL statement that needs to follow certain conventions.

To enter a new alert, use the System Administrator role to navigate to General Setup || Application || Alert window. Depending on how you installed Openbravo, you might already have some alerts here. If you do, try to find the Customers with exceeded credit one and double click it. If not, create a new record as indicated below:


CreateAlerts1.png

where this is the exact code for the SQL field:

 
 SELECT c_bpartner_id AS referencekey_id,
     ad_column_identifier('C_BPartner', c_bpartner_id, 'en_US') AS record_id,
     0 AS ad_role_id,
     NULL AS ad_user_id,
     ad_column_identifier('C_BPartner', c_bpartner_id, 'en_US') ||' has '||SO_CreditLimit||' as limit and has reached '||SO_CreditUsed AS description,
     'Y' AS isActive,
      ad_org_id, 
      ad_client_id, 
      now() AS created,  
      0 AS createdBy,  
      now() AS updated,
      0 AS updatedBy
 FROM c_bpartner 
 WHERE SO_CreditLimit < SO_CreditUsed
 AND iscustomer='Y'
 AND SO_CreditLimit!=0

The fields in question here are:

We will come back to this code and explain it in detail. First, let's try to see the resulting alert.

Definire destinatari

Switch to the Openbravo Admin role, navigate to General Setup || Application || Alert, double click the Customers with exceeded credit alert and switch to the Alert Recipients tab. Add a new record as indicated below:


CreateAlerts2.png


Notice that a role can be added (that includes several users) or a specific user.

Schedulare il processo di avvisi in background

For the alerts to be evaluated and triggered, the background process needs to be scheduled since it doesn't come that way out of the box. Using the Openbravo Admin role navigate to General Setup || Process Scheduling || Process Request and enter a new record:


CreateAlerts3.png

Il Risultato

Finally, log out and back in and switch to the Openbravo Admin role. You should be able to see the little red alert icon in the top right corner of the menu. By clicking on it, you will automatically be taken to the General Setup || Application || Alert Management window that should look something like:


CreateAlerts4.png


SQL code explained

In order to write any kind of alert, the approach is very similar. Let's take another look at the SQL code that describes the condition:

 
 SELECT c_bpartner_id AS referencekey_id,
     ad_column_identifier('C_BPartner', c_bpartner_id, 'en_US') AS record_id,
     0 AS ad_role_id,
     NULL AS ad_user_id,
     ad_column_identifier('C_BPartner', c_bpartner_id, 'en_US') ||' has '||SO_CreditLimit||' as limit and has reached '||SO_CreditUsed AS description,
     'Y' AS isActive,
      ad_org_id, 
      ad_client_id, 
      now() AS created,  
      0 AS createdBy,  
      now() AS updated,
      0 AS updatedBy
 FROM c_bpartner 
 WHERE SO_CreditLimit < SO_CreditUsed
 AND iscustomer='Y'
 AND SO_CreditLimit!=0

Each SQL statement basically simulates an Openbravo table which is why it needs to have all the columns defined above:

Finally the WHERE clause describes the condition that triggers the alert. In our case the SELECT statement will return all Business Partners (FROM c_bpartner) that are customers (iscustomer='Y') and have exceeded their credit limit (SO_CreditLimit < SO_CreditUsed) which needs to be different from zero (SO_CreditLimit!=0).

In other words, anything you can describe in a SQL statement can be defined as an alert. It's as simple as that.

Retrieved from "http://wiki.openbravo.com/wiki/ERP_2.50:Developers_Guide/How_to_develop_an_alert/it"

This page has been accessed 2,718 times. This page was last modified on 14 June 2011, at 11:04. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.