IBM Support

Sample onFault to send an email when a failure occurs.

Technical Blog Post


Abstract

Sample onFault to send an email when a failure occurs.

Body

The following is an example onFault that will send an email whenever a failure happens in a workflow.

The email will be sent to (and from) the admin account located in the sandbox.cfg file.

The email will contain a subject that reads "Business Process 9999999 failed"

It will be sent to the smtp host, email server, that is located in the sandbox.cfg.

The following bpml is set to fail so you can see how it works.

The lines in red bold is the onFault code that can be added to an existing bpml.

As always, please test the code out as needed in your test environment prior to implementing.

<process name = "onfault_test"> 

 <sequence>
  <operation name="File System Adapter">
   <participant name="EDIInboundFSAdapter"/>
    <output message="OutputMessage">
     <assign to="." from="*"></assign>
     <assign to="Action">FS_EXTRACT</assign>
     <assign to="extractionFolder">/folder/does/not/exist</assign>
    </output>
    <input message="inmsg">
     <assign to="." from="*"></assign>
    </input>
  </operation>

  <onFault>
   <sequence name="Sequence Start">
    <operation name="Business Process Metadata">
     <participant name="BPMetaDataInfoService"/>
      <output message="BPMetaDataServiceTypeInputMessage">
       <assign to="." from="*"></assign>
       <assign to="TRACE">TRUE</assign>
      </output>
      <input message="inmsg">
       <assign to="." from="*"></assign>
      </input>
    </operation>

    <operation name="XSLT Service">
     <participant name="XSLTService"/>
      <output message="XSLTServiceTypeInputMessage">
       <assign to="." from="*"></assign>
       <assign to="xslt_name">EmailOnError</assign>
       <assign to="xml_input_from">ProcData</assign>
       <assign to="input_pd_xpath">/</assign>
      </output>
      <input message="inmsg">
       <assign to="." from="*"></assign>
      </input>
    </operation>

    <assign to="MAIL_SUBJECT" from="concat('Business Process ',/ProcessData/BPDATA/WORKFLOW_ID/text(),' failed')"/>

    <operation name="Mail Mime Service">
     <participant name="MailMimeService"/>
      <output message="MailMimeServiceInputMessage">
       <assign to="." from="*"></assign>
       <assign to="mail-mime-subject" from="/ProcessData/MAIL_SUBJECT/text()"></assign> 
       <assign to="mail-mime-sender" from="sci-get-property('si_config','SI_ADMIN_MAIL_ADDR')"/>
       <assign to="mail-mime-recipient" from="sci-get-property('si_config','SI_ADMIN_MAIL_ADDR')"/>
       <assign to="mail-mime-operation">build</assign>
      </output>
      <input message="inmsg">
       <assign to="." from="*"></assign>
      </input>
    </operation>

    <operation name="SMTP Send Adapter">
     <participant name="SMTP_SEND_ADAPTER"/>
      <output message="SMTP_SEND_ADAPTERInputMessage">
       <assign to="." from="*"></assign>
       <assign to="xport-smtp-mailfrom" from="sci-get-property('si_config','SI_ADMIN_MAIL_ADDR')"/>
       <assign to="xport-smtp-mailto" from="sci-get-property('si_config','SI_ADMIN_MAIL_ADDR')"/>
       <assign to="xport-smtp-mailhost" from="sci-get-property('si_config','SI_ADMIN_SMTP_HOST')"/>
       <assign to="xport-smtp-mailport">25</assign>  
       <assign to="b2b-raw-message">true</assign> 
      </output>
      <input message="inmsg">
       <assign to="." from="*"></assign>
      </input>
    </operation>

   </sequence>
  </onFault>

 </sequence>
</process>

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SS3JSW","label":"IBM Sterling B2B Integrator"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11120575