Hi there,
I've spent a while searching for an answer on how I can create a scripted custom field based on another or copy one or add two together and am happy with all of that using scriptrunner
What I need to do is to is to have a scripted custom field where I change the last character for use in another custom field that does a database lookup.
I have a custom field that contains (for example) "12345A" or "123A".
What I want to do is to create another custom field that will replace the last letter in the string with "%" so that I end up with "12345%" or "123%"
Can anybody help me with a script fragment that that might allow me to say the equivalent of def newfield = left(oldfield,len(oldfield)-1 or similar
Thanks
Derek...
Hi, I got the following code working.
It's based on regex match so you can adapt it to suit your needs for the replacing. Example here takes the last ($) character ([A-Z]) and replace it with a %.
Hope this works for you.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfField = customFieldManager.getCustomFieldObject("customfield_10306")
def cfValue = issue.getCustomFieldValue(cfField)
def replacedValue = cfValue.toString().replaceAll(/[A-Z]$/, '%')
return replacedValue
That's excellent - should have thought of regex
Have included in my script and it does all I wanted!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.