Problem: You want to create a customer-facing notification when a Approval is needed for his/her request

Solution: Create a notification configuration like the following:


In TO section free-text expression add the following code snippet:


#foreach ($item in $!issue.lastchange.items)
  #if ($item.fieldId == "customfield_10210") 
    #set($newElems = $jirassimo.getNewElements($item.from, $item.to)) 
      #foreach ($e in $newElems)
        #foreach ($rp in $issue.fields.customfield_10210)
          #if ($rp.accountId == $e)
            $rp.emailAddress ,
          #end
        #end
      #end 
  #end
#end


Using "Issue field picker" button check out what's the proper custom field code that keeps "Approvers" in your system and replace  customfield_10210 in the code above to correct value. 


In the script above on line 2 we check that the "Approvers" field was changed and on the line 3 using $jirassimo.getNewElements() function we're retrieving all the new values that were added to that field during last issue update. Normally, it should be just 1 value, but you never know for sure...

After that, on line 4 we iterate through new values and compare them against all the Approvers in the request (line 5). If the new value is equal to the accountId of particular Approver then we know that this was recently added and we output Approver's email address on line 7. As a result, only newly added approvers will be added to the free-text TO section of emails.


We will also add extra check inside our Message template just in case you want to send also to other recepients (beside approvers), or/and you want to notify using CC/BCC. Here's the Message template:



#set($isApproverAdded = false)
#foreach ($item in $!issue.lastchange.items)
  #if ($item.fieldId == "customfield_10210" and $jirassimo.getNewElements($item.from, $item.to).size() gt 0 )
    #set($isApproverAdded = true)
  #end
#end

#if ($isApproverAdded)
   Your message template goes here...
#end


On line 9 you'll put the Notification template that will be rendered to the recepient of the notification. For convenience, feel free to use our Request approval required - template.html