ERP5 KM

HowToUseTheNotificationTool

What is The ERP5Notification Tool

The ERP5Notification tool provides a central point to send asynchronous messages from one user to one or many users. The purpose of the tool is to provide an API which is independent on how messages are actually going to be sent and when.

How to install

ERP5 is going to use ERP5Notification extensively. So, it is necessary to install it on systems before an upgrade. Since it is provided with the ERP5 product, you only need to go to the ZMI and add it by selecting 'Add ERP5 Tool'

The Notification Tool will be (soon) automatically created with a new site.

How to send a notification

Here is an example about how to send a notification from a workflow transition:

   1 """
   2 This script tries to send a message to the appropriate recipient
   3 from the appropriate sender. It uses portal_notifications
   4 and the getObject API of ERP5Catalog.
   5 """
   6 from Products.ERP5Type.Log import log
   7 
   8 object = sci['object']
   9 translateString = context.Base_translateString
  10 portal_catalog = object.portal_catalog
  11 
  12 # Get the owner
  13 owner = object.getViewPermissionOwner()
  14 owner_value = portal_catalog.getResultValue(portal_type='Person', reference=owner)
  15 
  16 # Get the authenticated user
  17 user = context.portal_membership.getAuthenticatedMember().getUserName()
  18 user_value = portal_catalog.getResultValue(portal_type='Person', reference=user)
  19 
  20 # If users are not defined, we need to log and return
  21 if not owner or owner_value is None:
  22   # We keep a trace because this is the best we
  23   # can do (preventing answers is even worse)
  24   log("ERP5 Query Workflow", "No owner defined")
  25   return
  26 if not user or user_value is None:
  27   # We keep a trace because this is the best we
  28   # can do (preventing answers is even worse)
  29   log("ERP5 Query Workflow", "Current user is not defined")
  30   return
  31 
  32 # Build the message and translate it
  33 subject = translateString("Query was answered")
  34 msg = """The Query ID ${id} which you posted has been answered by ${user}
  35 
  36 Question:
  37 
  38 ${question}
  39 
  40 Answer:
  41 
  42 ${answer}
  43 """
  44 msg = translateString(msg,
  45              mapping=dict(id=object.getId(),
  46                           subject=subject,
  47                           user=user_value.getTitle(),
  48                           question=object.getDescription(),
  49                           answer=object.getTextContent())
  50             )
  51 
  52 # We can now notify the owner through the notification tool
  53 context.portal_notifications.sendMessage(sender=user, recipient=owner, subject=subject, message=msg)

In this example, we provide user and owner as an object. However, it is also possible to provide them as a string or as a list (of object values or string). Future implementations may make unnecessary the validations which are made at the header of this script.

HowToUseTheNotificationTool (last edited 2008-01-03 13:48:05 by localhost)

Page
  • Immutable Page
  • Info
  • Attachments
User
Learn about new ERP5 releases,technical articles, events and more.

Subscribe to the monthly ERP5 Newsletter!