It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Contruct JQL based on label Edited

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

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.

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

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.

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

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)

 

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

HI @Jack Nolddor -Sweet Bananas- 

I tried above but not working.

test1.PNG

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

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
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

303 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you