Jython code not working in Jira

Issue #5 new
Lakshmi Durga Tammineni created an issue

Hi Team,

We have the following code on Jira Workflow post function to move the approvers from the default field who have approved on particular ticket and show the approved people names separately. On transition the code will send an email to approver group initially. After Jira upgrade the code is not working.

Kindly, go through the following code and provide necessary solution to make it work on Jira latest version.

This is breaking business use cases and please do needful ASAP

HTML Email Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd><html xmlns=http://www.w3.org/1999/xhtml><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
</head>
<body class="jira" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429">
<table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt" bgcolor="#f5f5f5">
<!-- header here -->
<tbody>
<tr>
<td id="header-pattern-container" style="padding: 0px; border-collapse: collapse; padding: 10px 20px">
<table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td id="header-text-container" valign="middle" style="padding: 0px; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"><strong>Request for Sign Off</strong></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td id="email-content-container" style="padding: 0px; border-collapse: collapse; padding: 0 20px">
<table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; border-spacing: 0; border-collapse: separate">
<tbody>
<tr>
<!-- there needs to be content in the cell for it to render in some clients -->
<td class="email-content-rounded-top mobile-expand" style="padding: 0px; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 15px; background-color: #ffffff; border-left: 1px solid #cccccc; border-top: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly" height="10" bgcolor="#ffffff"> </td>
</tr>
<tr>
<td class="email-content-main mobile-expand " style="padding: 0px; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff">
<table class="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td class="page-title-pattern-first-line " style="padding: 0px; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; padding-top: 10px"> <a href="${baseurl}/browse/${pkey}" style="color: #3b73af; text-decoration: none">${issue.project.name}</a> / <a href="${baseurl}/browse/${issue.key}" style="color: #3b73af; text-decoration: none">${issue.key}</a> </td>
</tr>
<tr>
<td style="vertical-align: top;; padding: 0px; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" class="page-title-pattern-header-container"> <span class="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="${baseurl}/browse/${issue.key}" style="color: #3b73af; text-decoration: none">${issue.summary}</a> </span> </td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="email-content-main mobile-expand wrapper-special-margin" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 10px; padding-bottom: 5px" bgcolor="#ffffff">
<table class="keyvalue-table" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<th style="color: #707070; font: normal 14px/20px Arial, sans-serif; text-align: left; vertical-align: top; padding: 2px 0">Description:</th>
<td style="padding: 0px; border-collapse: collapse; font: normal 14px/20px Arial, sans-serif; padding: 2px 0 2px 5px; vertical-align: top">$!{issue.description}</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="email-content-main mobile-expand wrapper-special-margin" style="padding: 0px; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; padding-top: 10px; padding-bottom: 5px" bgcolor="#ffffff">
<table class="keyvalue-table" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td style="max-width: 250px; background-color: #0077ff; valign="middle" width="250" align="center"><a style="font-size: 12pt; text-decoration: none; font-family: Segoe UI, Open Sans, Helvetica, Arial, sans-serif; color: #ffffff" href="${baseurl}/browse/${issue.key}" align="center"><font color="#ffffff">Signoff on One Jira</font></a></td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- there needs to be content in the cell for it to render in some clients -->
<tr>
<td class="email-content-rounded-bottom mobile-expand" style="padding: 0px; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #ffffff; border-top: 0; border-left: 1px solid #cccccc; border-bottom: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly" height="5" bgcolor="#ffffff"> </td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td id="footer-pattern" style="padding: 0px; border-collapse: collapse; padding: 12px 20px">
<table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0px; border-collapse: collapse; color: #999999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px">Please access to JIRA to make approval decision.</td>
<td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0px; border-collapse: collapse; padding-left: 20px; vertical-align: top">
<table style="border-collapse: collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt">
<tbody>
<tr>
<td id="footer-pattern-logo-desktop-padding" style="padding: 0px; border-collapse: collapse; padding-top: 3px"> </td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>

Code for reference: (To set approver field value to notify)

from com.atlassian.jira.component import ComponentAccessor
from datetime import datetime
from java.lang import Long
from java.util import ArrayList

# Declare environment variables
commentManager = ComponentAccessor.getCommentManager()
customFieldManager = ComponentAccessor.getCustomFieldManager()
groupManager = ComponentAccessor.getGroupManager()

# Retrieve custom field reference and value
customFields = customFieldManager.getCustomFieldObjects(issue)
for customField in customFields:
if customField.getFieldName() == "Approval Committee":
approvalCommittee = customField.getValue(issue)
elif customField.getFieldName() == "Approver":
approverRef = customField
approver = customField.getValue(issue)
elif customField.getFieldName() == "Approved By":
approvedBy = customField.getValue(issue)
elif customField.getFieldName() == "Attachment Count":
# Set attachment count
issue.setCustomFieldValue(customField, Long(ComponentAccessor.getAttachmentManager().getAttachments(issue).size()).doubleValue())
elif customField.getFieldName() == "Attachment Size":
# Set attachment size
filesize = 0L
for attachment in ComponentAccessor.getAttachmentManager().getAttachments(issue):
filesize = filesize + attachment.getFilesize()
issue.setCustomFieldValue(customField, Long(filesize).doubleValue()/1024/1024)
elif customField.getFieldName() == "Submitted Date":
# Set submitted date
issue.setCustomFieldValue(customField, datetime.today())

# Initialize approvalCommittee as ArrayList if it is blank
if approvalCommittee is None:
approvalCommittee = ArrayList()

# Initialize approver as ArrayList if it is blank
if approver is None:
approver = ArrayList()

# Initialize approvedBy as ArrayList if it is blank
if approvedBy is None:
approvedBy = ArrayList()

# Add users to approver
if approvalCommittee.getValue() == 'Life Sales and Operations Committee':
userGroup = groupManager.getUsersInGroup("change-control-lsoc")
elif approvalCommittee.getValue() == 'Product Development Committee':
userGroup = groupManager.getUsersInGroup("change-control-pdc")
elif approvalCommittee.getValue() == 'Unit Linked Investment Committee':
userGroup = groupManager.getUsersInGroup("change-control-ulic")
elif approvalCommittee.getValue() == 'Unit Pricing Committee':
userGroup = groupManager.getUsersInGroup("change-control-upc")
else:
userGroup = ArrayList()

for user in userGroup:
userFound = False
for approvedByItem in approvedBy:
if approvedByItem == user:
userFound = True
continue
if userFound == False:
approver.add(user)

# Store approver to issue
issue.setCustomFieldValue(approverRef,approver)
issue.store()

After upgrade it is not working, Kindly review once let me know if need any additional information .

Comments (0)

  1. Log in to comment