Hi,
I'm trying to fast-track issues based on a specific label. Ie, if label X if set then fast track (transition) the issue.
Here's the code I was using:
def issueLabels = issue.fields.labels
boolean containsLabel = false;
for (String label : issueLabels) {
if (label ==~ /(?i)test/){
containsLabel = true;
}
}
This code doen't fail but also doesn't work (Ie, issues with 'test' or 'Test' label are not transitioned).
Thanks,
Yuval
Hi @Yuval Oren
Try getting labels using
import com.atlassian.jira.issue.label.LabelManager
...
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def issueLabels = labelManager.getLabels(issue.id)
Thanks @Tom Lister. When I tried the following code I got these errors:
unable to resolve class com.atlassian.jira.component.ComponentAccessor
unable to resolve class com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.label.LabelManager;
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager);
def issueLabels = labelManager.getLabels(issue.id);
boolean containsLabel = false;
for (String label : issueLabels) {
if (label ==~ /(?i)test/){
containsLabel = true;
}
}
Note: This runs on Jira cloud.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Yuval Oren
I’m a server guy unfortunately
looking at the migration guide here
http://scriptrunner-docs.connect.adaptavist.com/jiracloud/migrating.html#_logging
the cloud version use the REST API’s rather than plugin API
e.g.
def customFields = get("/rest/api/2/field")
.asObject(List) .body
.findAll { (it as Map).custom } as List<Map>
def toUpdate1CfId = customFields.find { it.name == 'Custom Field 1' }?.id
def toUpdate2CfId = customFields.find { it.name == 'Custom Field 2' }?.id
def toUpdate3CfId = customFields.find { it.name == 'Custom Field 3' }?.id
thats as far as I can go with this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tom Lister thanks for pointing me in the right direction :-)
I now have this code which works for me:
int total = post('/rest/api/2/search')
.header('Content-Type', 'application/json')
.body(
[
jql: 'issuekey=' + issue.key + ' and labels in (test)',
fields: ["key"]
]).asObject(Map).body.total
total == 1
Basically using JQL result to evaluate the condition. I assume this could probably be achieved in a more efficient way but this solution works for Jira cloud.
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.