Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

scriptrunner Matcher cannot be cast to java.lang.Double

Edited

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!

1 answer

0 votes

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})/

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

102 views 1 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you