Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,457,751
Community Members
 
Community Events
176
Community Groups

Customfields with spaces in a Scriptrunner JQL expression

I am trying to use the "expression" function in scriptrunner for jql. But my customfields have a space in their name and hence I am getting an error.

This is the jql I am trying:

issueFunction in expression("", "\"ABC D\" = \"EFG H\"")

Can you please help me with the correct way to write such a query? I was also looking at ways where I can specify the customfield ids rather the names but couldn't find it.

1 answer

1 vote
Mohamed Adel Community Leader Aug 20, 2018

Hi Keval, 

Could you please specify what is the type of your custom field, i.e. number, date or string values?

 

thanks 

Adel

both the custom fields are strings

Mohamed Adel Community Leader Aug 20, 2018

The problem is that IssueFunction doesn't support custom fields with spaces as mentioned here, also IssueFunction can help as long as your custom fields are date, datetime or numeric fields only. 

oh! thats strange. thanks for this info
is there any other way I can compare this?

Well Keval you can use the issueFieldMatch to query any field by regular expression. 

And as you mentioned if your field has spaces the you can use the id of the field, so for example, in order to find out all the fields that the custom field with id customfield_10300 contains the character a you will need something like 

issueFunction in issueFieldMatch("", "customfield_10300", "a")

PS. A quick way to find the id of your custom field will be to go to your Script Console and run the following script 

import com.atlassian.jira.component.ComponentAccessor

ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Text Field").id

Hope that helps, 

Thanos

Like Joshua Giffen likes this

Thanks @Thanos Batagiannis [Adaptavist]

I checked out the issueFieldMatch function and its great to match against a constant value. But, in my case I would like to compare two custom fields and I believe that's not possible. Let me know if I am wrong.

Mohamed Adel Community Leader Aug 21, 2018

Hi keval,

i would recommend to have another scriptfield to compare the two values and return True/False 

 

if this can solve your problem we can work on it for you 

Yes. That's indeed a good idea.

However I believe this should be very native feature to JQL as having the above solution is good in a case or two. But when this is to be done across many fields, it wouldn't be elegant.

Hi Keval, 

Kindly, create a scripted filed custom field (Free Text Srearcer) and use the following script: 

 

After that you can use JQL to search for True/False values. 

 

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger

def CustomFieldManager = ComponentAccessor.getCustomFieldManager()

def log = Logger.getLogger("")

def customfield1 = CustomFieldManager.getCustomFieldObjectByName("ABC D")
def customfield2 = CustomFieldManager.getCustomFieldObjectByName("EFG H")

if (issue.getCustomFieldValue(customfield1) == issue.getCustomFieldValue(customfield2)) {
return "True"
}
else {
return "False"
}

 

I hope this will help you

Regards

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events