Hello Team,
Based on Issue Type - “Bug” and Custom Field - “SubDelivery” (Select list) Specific Value , Auto comment needs to be updated.
Please Find Comment Template that needs to be updated in comment section. PFA
When we tried to update comment in table format in post function, it was not working. kindly help us to resolve this issue.
This code is currently under investigation by my side. You may make suggestions or contribute alternative code.
Script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
// Replace 'CUSTOM_FIELD_ID' with the ID of your custom field "SubDelivery"
def customFieldName = 'Sub-Delivery'
// Create the table format comment
def tableComment = """
|| Heading 1 || Heading 2 || Heading 3 ||
| Value 1 | Value 2 | Value 3 |
| Value A | Value B | Value C |
"""
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def commentManager = ComponentAccessor.getCommentManager()
// Get the issue that triggered the event
Issue eventIssue = event.issue
def customField = customFieldManager.getCustomFieldObject(customFieldName)
if (eventIssue && customField) {
// Get the current value of the custom field "SubDelivery"
def subDeliveryValue = eventIssue.getCustomFieldValue(customField)
// Check if the value of the custom field "SubDelivery" is "ABC"
if (subDeliveryValue == "ABC") {
// Add the table format comment
commentManager.create(eventIssue, event.user, tableComment, true)
// Log message (optional)
log.info("Table format comment added for issue ${eventIssue.key}.")
} else {
// Log message (optional)
log.info("No action needed for issue ${eventIssue.key}.")
}
} else {
log.error("Issue or custom field not found.")
}
But we are getting “Issue or custom field not found” in logs