You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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.