Automated Issue Comment using Groovy Script

Jeremy Outlaw
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 30, 2024

Good Afternoon

I am hoping someone is able to provide some insight as to why the following script does not work. I am attempting to use custom script to have comments placed on an issue dependent on a custom field value.

I am using the following script but I am not having any luck:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.Issue
 
// Get the issue object
issue = issue.getIssueType("TWU - Wires")
 
// Get the custom field value
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject("TWU - Call Back")
def customFieldValue = issue.getCustomFieldValue("TWU - Call Back")
 
// Define the comment manager
CommentManager commentManager = ComponentAccessor.getCommentManager()
 
// Add a comment based on the custom field value
if (customFieldValue == "Call back completed using two step verification") {
    commentManager.create(issue, issue.reporter, "Call back completed using two step verification", true)
} else if (customFieldValue == "Call back completed - Client is ineligible for two step verification - Client has no SSN on file") {
    commentManager.create(issue, issue.reporter, "Call back completed - Client is ineligible for two step verification - Client has no SSN on file", true)}
    else if (customFieldValue == "Call back completed - Client is ineligible for two step verification - Client's contact info does not validate via Innovis") {
    commentManager.create(issue, issue.reporter, "Call back completed - Client is ineligible for two step verification - Client's contact info does not validate via Innovis", true)}
    else if (customFieldValue == "Call back completed - Client is ineligible for two step verification - Wire authorized agent is not account signer, no SSN on file") {
    commentManager.create(issue, issue.reporter, "Call back completed - Client is ineligible for two step verification - Wire authorized agent is not account signer, no SSN on file", true)}
    else if (customFieldValue == "Call back completed for Consumer International Wire using two step verification") {
    commentManager.create(issue, issue.reporter, "Call back completed for Consumer International Wire using two step verification", true)}
    else if (customFieldValue == "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Client has no SSN on file") {
    commentManager.create(issue, issue.reporter, "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Client has no SSN on file", true)}
    else if (customFieldValue == "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Client's contact info does not validate via Innovis") {
    commentManager.create(issue, issue.reporter, "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Client's contact info does not validate via Innovis", true)}
    else if (customFieldValue == "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Wire authorized agent is not account signer, no SSN on file") {
    commentManager.create(issue, issue.reporter, "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Wire authorized agent is not account signer, no SSN on file ", true)
 
} else if (customFieldValue == "Call back is not required per Call Back Internal Matrix") {
    commentManager.create(issue, issue.reporter, "Call back waived per Matrix.", true)
}

 

1 answer

0 votes
Doreen Undiri
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2024

Hi  @Jeremy Outlaw ,

Am not so good with groovy script so I asked one of my friend to help check your script,  and this was his output

 

  • The line issue = issue.getIssueType("TWU - Wires") is likely causing a problem. issue.getIssueType("TWU - Wires") is not a valid method to get an issue object,  if you’re running this script within a workflow transition or an event listener, issue should already represent the current issue, so no need to reassign it.
  • You need to use the custom field object to retrieve its value from the issue. Currently, issue.getCustomFieldValue("TWU - Call Back") is incorrect. Instead: def customFieldValue = issue.getCustomFieldValue(customField)

 

He revised the codes,

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.Issue

// Get the custom field value
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("TWU - Call Back")
def customFieldValue = issue.getCustomFieldValue(customField)

// Define the comment manager
CommentManager commentManager = ComponentAccessor.getCommentManager()

// Add a comment based on the custom field value
if (customFieldValue == "Call back completed using two step verification") {
commentManager.create(issue, issue.reporter, "Call back completed using two step verification", true)
} else if (customFieldValue == "Call back completed - Client is ineligible for two step verification - Client has no SSN on file") {
commentManager.create(issue, issue.reporter, "Call back completed - Client is ineligible for two step verification - Client has no SSN on file", true)
} else if (customFieldValue == "Call back completed - Client is ineligible for two step verification - Client's contact info does not validate via Innovis") {
commentManager.create(issue, issue.reporter, "Call back completed - Client is ineligible for two step verification - Client's contact info does not validate via Innovis", true)
} else if (customFieldValue == "Call back completed - Client is ineligible for two step verification - Wire authorized agent is not account signer, no SSN on file") {
commentManager.create(issue, issue.reporter, "Call back completed - Client is ineligible for two step verification - Wire authorized agent is not account signer, no SSN on file", true)
} else if (customFieldValue == "Call back completed for Consumer International Wire using two step verification") {
commentManager.create(issue, issue.reporter, "Call back completed for Consumer International Wire using two step verification", true)
} else if (customFieldValue == "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Client has no SSN on file") {
commentManager.create(issue, issue.reporter, "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Client has no SSN on file", true)
} else if (customFieldValue == "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Client's contact info does not validate via Innovis") {
commentManager.create(issue, issue.reporter, "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Client's contact info does not validate via Innovis", true)
} else if (customFieldValue == "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Wire authorized agent is not account signer, no SSN on file") {
commentManager.create(issue, issue.reporter, "Call back completed for Consumer International Wire - Client is ineligible for two step verification - Wire authorized agent is not account signer, no SSN on file ", true)
} else if (customFieldValue == "Call back is not required per Call Back Internal Matrix") {
commentManager.create(issue, issue.reporter, "Call back waived per Matrix.", true)
}

 

Goodluck I hope it helped


Dd

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events