Hi there community.
I am trying to copy over the value of a label cf called 'Support Request Label' from the Epic to a Support Request within a behaviour initialiser.
Although technically the script I have is copying the field value...it is adding brackets. Is there anyone out there that know how to get rid of these?
Any help is appreciated.
Epic create screen:
Script (partial) behind create screen pop up after clicking on Request Support:
//create screen when creating from IT project
if (getBehaviourContextId() == "link-create-support-request-IT") {
getFieldById("project-field").setReadOnly(true)
getFieldById("issuetype-field").setReadOnly(true)
def contextIssue = issueManager.getIssueObject(getContextIssueId())
getFieldById("issuelinks-linktype").setFormValue("epics requiring support").setReadOnly(true)
getFieldById("issuelinks-issues").setFormValue(contextIssue.key).setReadOnly(true)
//below does copy the value, but adds brackets
//getFieldById("customfield_18300").setFormValue("${contextIssue.getCustomFieldValue("Support Request Label")}").setReadOnly(true)
//below adds test without brackets but this is not what I want
//getFieldById("customfield_18300").setFormValue("test")
//below does copy the value, but brings in brackets as well
getFieldByName("Support Request Label").setFormValue(contextIssue.getCustomFieldValue("Support Request Label").toString())
}
contextIssue.getCustomFieldValue("Support Request Label")
returns a Set<Label> (https://docs.atlassian.com/software/jira/docs/api/9.12.8/com/atlassian/jira/issue/label/Label.html), so the brackets are coming from the .toString() method because it is converting a set(=collection) to String
I don't know the format for setting labels in behaviours, so might want to experiment with it a bit to get it to work for multiple labels, but if you want to confirm this on this particular case where you only have a single element in the set, you could do
getFieldByName("Support Request Label").setFormValue(contextIssue.getCustomFieldValue("Support Request Label")?.first()?.getLabel())
And that should go without brackets.
If you want to handle more cases, I'd say it would be better to first store the value as a variable
Set<Label> labels = (Set<Label>) contextIssue.getCustomFieldValue("Support Request Label")
And then handle it in some way such as
if (labels != null && !labels.isEmpty()) {
// has values
List<String> labelValues = labels.stream().map(l -> l.getLabel()).collect(Collectors.toList())
for (String labelValue : labelValues) {
// do something per value
}
// or do something with the list, such as
String spaceDelimitedLabelValues = String.join(" ", labelValues)
}
else {
// null or no values so whatever
}
Again though I don't know the exact format with labels, would need to find some time to play around with it but if you have a test case already it's probably better for you to experiment with it a bit to know how it works in practice.
This worked. Thanks so much for your explanation! Appreciate your help.
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.