Warning

This document hasn't been checked for compatibility with current versions of Plone. Use at your own risk.

Send mail on a workflow transition

by Alan Runyan last modified Dec 30, 2008 03:02 PM
Shows how to send an email when a workflow transition is triggered, for example to notify content owners that their document has been rejected.

The example below shows how to create a script called reject_notification which is triggered on the reject workflow transition in order to send an email to the content submitter explaining that their document was rejected. It can of course be adapted to send different messages on different transitions easily.

Workflow Configuration:

  • In the ZMI goto portal_workflow
  • click the scripts tab
  • add a new Script (Python)
  • id: reject_notification
  • parameter list: sti
  • body:
        obj=sti.object
        creator = obj.Creator()
        history = sti.getHistory()
        wf_tool = context.portal_workflow
    
        mMsg = """
        Your submission was rejected.
        The url was %s.
        The reason was %s.
        """
    
        member = context.portal_membership.getMemberById(creator)
        creator = {'member':member,
                   'id':member.getId(),
                   'fullname':member.getProperty('fullname', 'Fullname missing'),
                   'email':member.getProperty('email', None)}
    
        actorid = wf_tool.getInfoFor(obj, 'actor')
        actor = context.portal_membership.getMemberById(actorid)
        reviewer = {'member':actor,
                    'id':actor.getId(),
                    'fullname':actor.getProperty('fullname', 'Fullname missing'),
                    'email':actor.getProperty('email', None)}
    
        mTo = creator['email']
        mFrom = reviewer['email']
        mSubj = 'Your item has transitioned'
        obj_url = obj.absolute_url() #use portal_url + relative_url
        comments = wf_tool.getInfoFor(obj, 'comments')
    
        message = mMsg % (obj_url, comments)
        context.MailHost.send(message, mTo, mFrom, mSubj)
    
  • click save

Now we have added the script that does the transition. We want to wire this script to the reject transition.

  • click the transitions tab in the ZMI
  • click the reject transition
  • in the Script (after) drop down select the reject_notification
  • click Save

Now whenever you reject a piece of content it will email the person who created the content. It will also say say it came from the person who rejected the document.


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.