Contruct JQL based on label

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2019

I have a label type custom field using which i'm writing the behavior script.

Whenever i am selecting the first-time label then the JQL is working, but How to construct JQL with multiple labels using a script. 

 

2 answers

1 accepted

0 votes
Answer accepted
Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2019

HI @Jack Nolddor _Sweet Bananas_ 

Finally  the below line works fine.

String test = lList.get(i).toString().replaceAll("\\[","").replaceAll("\\]","")

thanks for your help and quick response.

1 vote
Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 31, 2019

Hi Yogest,
Could you further explain your requirements?

You can use the IN operator to search for multiples labels at the same time, e.g.:

 

labels IN ("customer", "delay", "deploy")


Regards

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2019

HI @Jack Nolddor _Sweet Bananas_ 

Thanks for the response.

Actually the requirement is ...we have a label type custom field on crate screen so whenever a user will select the existing label then it should give an error that means we don't want user should select the existing label to avoid duplication because the same label is already used by one of the Jira issues.

So I have written then server-side behavior using which I'm checking whether the provided label is used or not...if not then the user should go ahead and crate issue.

 The current script is working fine with single value but if the user selects multiple label then how I can add those label in JQL to check whether all the provided label is used or not.

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2019

The current script returns the JQL result in the below format ..because of the square bracket the JQL is failing.

So i wanted to replace square bracket with an empty string in JQL 

test.PNG

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2019
def testLabel = getFieldById("customfield_11100")
def testLabel_value = testLabel.getValue()
System.out.println(" @@@@ Values " + testLabel_value)
ArrayList lList = new ArrayList<>(Arrays.asList(testLabel_value))
//ArrayList<String> lList = new ArrayList<>(Arrays.asList(testLabel_value));
for (int i = 0; i < lList.size(); i++)
{
String test = lList.get(i).toString()//.replaceAll("\\[]", "()")
System.out.println(" @@@@ Search Iteam : " + lList.get(i))
System.out.println(" @@@@ Search test : " + test)
String jqlSearch ="project=DEM and issuetype = Bugs and cf[11100] in ($test)";
SearchService searchService = (SearchService) ComponentAccessor.getComponent(SearchService.class);
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch);
System.out.println("@@@ JQL Result : " + jqlSearch)

 

Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 31, 2019

Do you mind to change this line:

 

String jqlSearch ="project=DEM and issuetype = Bugs and cf[11100] in ($test)";

 

with the following?

String jqlSearch ="project=DEM and issuetype = Bugs and cf[11100] in (${testLabel_value.join(', ')})";

Regards

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2019

HI @Jack Nolddor _Sweet Bananas_ 

I tried above but not working.

test1.PNG

Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 31, 2019

I've updated my previous reponse.
Could you check?

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 31, 2019

checked but not getting field values itself

I tried below...but now I need to add a comma (,) in between two labels..

for (int i = 0; i < lList.size(); i++)
{
String test = lList.get(i).toString().replaceAll("\\p{P}","")
System.out.println(" @@@@ Search Iteam : " + lList.get(i))
System.out.println(" @@@@ Search test : " + test)
String jqlSearch ="project=DEM and issuetype = Bugs and cf[11100] in ($test)";
//String jqlSearch ="project=DEM and issuetype = Bugs and cf[11100] in (${test.join(', ')})";
SearchService searchService = (SearchService) ComponentAccessor.getComponent(SearchService.class);
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch);
System.out.println("@@@ JQL Result : " + jqlSearch)

test2.PNG

Suggest an answer

Log in or Sign up to answer