Skip to Content

Customize Alerts Using Job in PI 7.31/PO

Recently, I had a requirement in my project where my client wants a notification to be send to their external event monitoring system (via a JMS protocol) as soon as there is any failure in identified business critical interfaces. After hearing this requirement, below nice article came to my mind.

But having said so, I was not very keen in implementing “Alert” interfaces in my landscape and looking for something more generic. So, I started wondering (?), why I cannot create and schedule my own job (somewhat similar to “AlertConsumerJob”) which will keep on inquiring interface status (using AlertRetrieveAPI) and in case of any failures read alerts from the alert store (i.e. Consumer) and report the error logs in a more readable format – just thought of mentioning it 😉 .

So, here below I am showing how we can create a custom job in PI/PO (in just 6 simple steps – yeah that’s true 🙂 ) which will consume alerts from the alert store using “AlertRetrieveAPI” and format the alert text.

Step 1: Create EJB (CustomJOB) and its corresponding EAR (CustomJOB_EAR) project and then import below jar files in your ejb project.

a) engine.jee5.facade.jar

b) jee5.facade.jar

c) tc~je~scheduler~api.jar

Step 2: Create one java class (in my case I have named it as Custom_Job) and start coding the business logic inside OnJob() method.

At runtime, job will execute the logic which is written inside onJob() method.

package com.customjob;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import java.util.logging.Level;
import java.util.logging.Logger;
 * Message-Driven Bean implementation class for: Custom_JOB
@MessageDriven(activationConfig = {
 @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
 @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "JobDefinition='Custom_JOB'")
public class Custom_JOB extends MDBJobImplementation {
     * Default constructor.
             * @see MessageListener#onMessage(Message)
    public void onJob(JobContext ctx) {
    Logger log = ctx.getLogger();
    try {
    JobParameter Alert_URL = ctx.getJobParameter("Alert_URL");
    JobParameter Consumer = ctx.getJobParameter("Consumer");
//Cosume alerts from the alert store using custom "ConsumerURL" method
    RetrieveAlert.ConsumeURL(log, Alert_URL.getStringValue(), Consumer.getStringValue());
 catch (Exception e) {
    log.log(Level.SEVERE, e.toString(), e);
    throw new RuntimeException(e);

Few points to remember:

a) destinationType: Value of property “destinationType” should always be “javax.jms.Queue”.

b) messageSelector: Value of property “messageSelector” can be set as your “Job Name” (in my case it is Custom_Job). In fact, you can choose any name over here, but make sure the “JobDefinition” name which you have defined over here has to be identical with the name of job definition (which you will define later in step 4) in job-definition.xml deployment descriptor file.

c) OnJob() method: Inside this method you have to code the business logic that the instance of the job definition should perform at runtime.

d) JobContext Interface: Using this you can access a logger object to write job logs in the database. In addition to that, you can read job parameters from PI (which you will define while scheduling jobs in NWA) using getJobParameter method.

e) “ConsumeURL” method : For a clarity purpose, i have created a separate method named as “ConsumeURL” which will perform the task of consuming alerts from store using “AlertRetrieveAPI” and formatting the alert text.

Step 3: Edit “ejb-j2ee-engine.xml” deployment descriptor file.

<?xml version="1.0" encoding="UTF-8"?>
<ejb-j2ee-engine xmlns:xsi="">
      <jndi-name> CustomAlert</jndi-name>

Points to remember:

a) You have to specify “JobQueue” as the destination name, and “JobQueueFactory” as the connection factory name as shown in the code sample above.

b) You have to specify bean name (in my case it’s Custom_JOB) as your ejb-name.

Step 4: Create “job-definition.xml” deployment descriptor file from scratch and then edit the same with below sample code.

<?xml version="1.0" encoding="UTF-8"?>
 <job-definition name="Custom_JOB"
        description="Retrieve SAP PO Alerts from Consumer">
                                <job-definition-parameter name="Alert_URL"
                                                data-type="String" direction="IN"/>
                                <job-definition-parameter name="Consumer"
                                                data-type="String" direction="IN"/>

Job-definition.xml is an additional descriptor which identifies the deployed message driven bean as a JobBean.

Important: In the job-definition.xml file, you have to specify the name of the job definition and it has to be the same as the job name specified in the message selector in the JobBean class (i.e. Custom_JOB, refer step 2.b).

In addition to that, you have to declare the name, data type, and direction of the job parameters used in the Custom_JobBean class. The same parameters you will see while scheduling job in NWA (refer step 6).

Step 5: Open EAR project (CustomJOB_EAR) and edit application-j2ee-engine.xml file with below sample code.

<?xml version="1.0" encoding="UTF-8"?>
<application-j2ee-engine xmlns:xsi="">
  <reference reference-type="hard">
    <reference-target provider-name="" target-type= "service">


Step 6: Deploy EAR file on PO server and eventually schedule your custom job.


Provide values to the input parameters while scheduling custom job (i.e “AlertRetrieveAPI” Endpoint URL and Consumer Name)


And here you go 🙂


Conclusion: The steps which I have explained above will hold true while creating any custom job in SAP PI/PO and IMO, this could be useful in many types of scenarios. In fact, a replica of “AlertConsumerJob” can also be created and alerts can be send to email server in a desirable format.

References: – Details about how to register custom consumer using standard API

You must be Logged on to comment or reply to a post.
  • Hi Amit,

    Sincerely, this is an exceptional contribution. From my point of view the standard alert monitoring of PI has a little gaps and the examples of using these APIs are very useful to people like me that we come from ABAP world.


  • Hi Amit,

    This blog is very helpful.

    In the blog, i can see a new alert consumer (Test) has been used and configured.

    It would be great if you could let me know the steps in creating new alert consumer.

    Thanks in Advance!



  • Hi all,

    Very useful contribution but I have an issue following this method. When I deploy the EAR file and ask to schedule the task to be executed recursively, the javabean file is run only the first time. To run again the javabean I have to redeploy the component. Could you please help me on this issue ?

    Many thanks by advance,

    Fabien Simoens

    • Hello,

      I haven't faced anything like this while scheduling jobs, so i can only say that just make sure u are properly specifying start/end date and period.


      Amit Srivastava

      • Hi Amit,

        Thanks for your quick response. I confirm that start date, end date and period are correct, I can see that job has been run on each period ...

        Thanks by advance,

        Fabien Simoens

  • Hi Amit,

    Nice blog.I just started working on this in our PI server .Can you please suggest where can i find the above mentioned jar files ?

    I checked with my BASIS team ,but no luck .Could you please help me on this .




  • Hi Amit,

    It's indeed useful blog, I wonder, how email's formatting was done in Consumer_URL method, also how can we verify the scheduler's name i.e whether the values are coming from AlertRetrieverAPI or some other API's? 


    BR, Neha

  • Hello,

    nice blog.....

    Is it possible, that you add the "project" to this blog, so that we can see the ProjectType, where e.g. the "job-definition.xml" have to be placed and how you retreive the URL API...?

    Thank you.



  • Hi Amil,

    This is a great blog. We have similar requirement and i am looking for sample code for the custom class RetrieveAlert  and  method ConsumeURL ?

    Is it possible to share the same

    Kind Regards


  • Hello Amit,

    Its really a very helpful blog. Thanks a lot for the blog. I have a similar requirement wherein I need to customize the alert subject. Need to know if I can use the similar code?

    Also as the logic is in the class RetrieveAlert . Can you please let me know the code to be written in this class? Also being new to SAP PO and JAVA coding in it would like to know which tool to be used to compile this code and which view /steps to be used in NWDS to deploy it to SAP PO.

    Really appreciate your valuable inputs. Its really very urgent.

    Thanks in advance