Missed Team ’24? Catch up on announcements here.

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

Customfields with spaces in a Scriptrunner JQL expression

keval.doshi August 20, 2018

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.

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Mohamed Adel
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.
August 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

keval.doshi August 20, 2018

both the custom fields are strings

Mohamed Adel
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.
August 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. 

keval.doshi August 20, 2018

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

Thanos Batagiannis [Adaptavist]
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.
August 20, 2018

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
keval.doshi August 20, 2018

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
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.
August 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 

keval.doshi August 21, 2018

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.

Mohamed Adel
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.
August 21, 2018

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

0 votes
nimishagarg 2010
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 10, 2023

where these functions ae re writen in jira 

TAGS
AUG Leaders

Atlassian Community Events