Hi Atlassian Community!
The scenario I have is a multiselect custom field that I want to copy to a label type customfield (Not the issue label)
The issue I'm having is I can't copy the values one to one, I need to append the keyword "skill#" before each value returned by the multiselect, and replace all spaces with "_".
one thing that kinda worked was: "skill#" + findReplaceAll(%{issue.cf19904}, " ", "_")
That works great if I'm selecting one item, however for multiple I get:
skill#This_Is_The_First_Item,_This_Is_The_Second_Item
I'm wondering if there's a "for each" in the return of a multiselect. I understand a multiselect returns a string, not a list, but if I try toStringList(%{issue.cf19904},","), I get a generic error in JWT:
I was able to achieve what I need using scriptrunner, but I'd really prefer to do it in JWT instead if possible.
For those curious, this is my script in scriptrunner:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.label.Label
import com.atlassian.jira.issue.label.LabelManager
CustomField skillsList = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_19904")
def skillsListValue = issue.getCustomFieldValue(skillsList)
CustomField skillsLabel = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_15300")
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def labelManager = ComponentAccessor.getComponent(LabelManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def skillFieldID = customFieldManager.getCustomFieldObject("customfield_15300").getIdAsLong()
def joinedList = skillsListValue.collect { "skill#$it" }
joinedList = joinedList.collect {it.toString().replaceAll(" ", "_")}
for (skill in joinedList){
labelManager.addLabel(currentUser, issue.getId(), skillFieldID, skill, false)
}
Thank you all in advance
Hi Pierre Ibrahim!
I'm Nacho, support member of Decadis AG.
When using the "Advanced text" parsing mode, the result returned has to be a text, so you would have to use the parser function toString() to transform the result to a text.
If I understood correctly, it could be separated in the following way, by using toStringList() and findReplaceAll() in order to operate with each element o the list (seed):
toString(textOnStringList(toStringList(%{issue.cf19904}), "#skill" + findReplaceAll(%{seed.text}, " ", "_")))
Is this the result that you are looking for?
If not, I invite you to create a ticket in our support portal so we can have a more convenient and fluid communication!
I look forward to hearing from you.
Best regards,
Nacho
Hi @Nacho Moreno Ortega ,
Thank you so much for your response, I greatly appreciate it!
Unfortunately no, this brings back the same result as using "skill#" + findReplaceAll(%{cf}, " ","_")
What I'm looking for is really a way to loop over every element of a multiselect value, append "skill#" to the beginning of every value (not just the first value), and in every value, replace every instance of " " with "_".
For reference, let's say I have the following selections in my multiselect:
using the formula you provided I get the following
skill#This_Is_The_First_Value,_This_Is_The_Second_Value,_This_Is_The_Third_Value
vs what I need which is:
skill#This_Is_The_First_Value,skill#This_Is_The_Second_Value,skill#This_Is_The_Third_Value
I'm able to achieve this today using scriptrunner, but the problem here is it looks ugly in the issue history since scriptrunner has to add the values one by one to labels, I'm hoping by using JWT, I'm passing all the values at once to my labels field, and it would show just once in the issue history.
Edit: My apologies, your solution works perfectly! I was writing it incorrectly, thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.