I'll admit I'm not very good at this and have been struggling for days. I've actually reached the end of the information highway and resorted to going 3 pages deep in Google. I'm trying to use ScriptRunner (Listeners) during a issue creation to match description field with Regex (which works) and then insert into a Custom Field. I feel like I'm close, but I'm now having issues with data conversion:
java.util.regex.Matcher cannot be cast to java.lang.Double
I'm guessing it's barking about the Description field which I did getClass:
description: class java.lang.String
I know the Custom Field is a Number Field, since I created it. Here's what I've written, please don't beat up on my:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import java.util.regex.Matcher
import java.util.regex.Pattern
log.error("LogStart")
def issueManager = ComponentAccessor.getIssueManager()
log.error("Key: " + event.issue.getKey())
log.error("LogEnd")
def currentIssue = issueManager.getIssueObject(event.issue.getKey())
log.error("issue: " + currentIssue)
log.error("description: " + currentIssue.description)
log.error("description: " + currentIssue.description.getClass())
Matcher RegExResult = (currentIssue.description =~ /Member Number:.*?} ([1-9][0-9]{4,22})/)
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Foo Number"}
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), RegExResult),changeHolder)
I'd appreciate any help or input, this has been very frustrating - Thanks in advance!
If you want to access specific capture groups in your matcher, you need something like
RegExResult[0][1]
If you run this in the console
def test = "something Member Number: } 112346 something else"
def RegExResult = test =~ /Member Number:.*?} ([1-9][0-9]{4,22})/
RegExResult[0]
You will get an array result like this:
[Member Number: } 112346, 112346]
The first item in the array if the full match. Each subsequent item is a capture group.
So to get the actual number, you want to first match [0] and the second item in the list [1]
But you may have an error in your pattern, are you really expecting a } after Member Number?
If you want to find 1123456 in a string like "something Member Number: 112346 something else", then your pattern should be /Member Number:.*?([1-9][0]9{4,22})/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.