New to Scriptrunner. Developing script to update custom field value from last issue comment using RegEx. The target string format in the comment is "Ticket#123456". Getting error result when testing in Scriptrunner console
class com.riadalabs.jira.plugins.insight.common.exception.GroovyInsightException
GroovyInsightException: No such property: event for class: Script1'
Would appreciate any information on the nature of the error.
Thanks!
import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.opensymphony.workflow.InvalidInputException
import java.util.regex.Matcher
import java.util.regex.Pattern
// Event listener - listening for the Issue Commented event
def event = event as IssueEvent
def issue = event.issue as Issue
def comment = event.getComment()
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "TicketNum"}
def changeHolder = new DefaultIssueChangeHolder()
// Run RegEx against last comment to find ticket number
if (comment) {
// String to be scanned
String lastcomment = comment.body
// Regex patterns
String regex1 = "Ticket#[0-9]+"
String regex2 = "[0-9]+"
// Create pattern1 object
Pattern r1 = Pattern.compile(regex1)
// Create matcher1 object
Matcher matcher1 = r1.matcher(lastcomment)
if (matcher1.find( )) {
String result1 = matcher1
// Create pattern2 object
Pattern r2 = Pattern.compile(regex2)
// Create matcher2 object
Matcher matcher2 = r2.matcher(result1)
if (matcher2.find( )) {
String result2 = matcher2
}
// Assign result2 value to custom field "TicketNum"
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), "result2"),changeHolder)
}
}