How can I reference the custom field ID rather than its name in a Scriptrunner JQL query?

Nadine Schuett February 22, 2022

Hello Community

I am using a ScriptRunner JQL to find issue which have been created after the "Start Date" custom field.

issueFunction in dateCompare("", "created > Start Date")

This works well but now we run into a problem due to having two custom fields of the same type with the same name.

Does anyone how whether I can reference the customfield ID in the query rather than the name?

Also, I am fully aware that the correct way would be to clean up our Jira and avoid two custom fields of the same type and name but I need a shortcut now.

Many thanks

1 answer

1 accepted

2 votes
Answer accepted
carlosughini
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 22, 2022

Hi Nadine,

Using custom field's IDs rather than their names is a really good choice. Custom fields will have their ID next to the name of the field when suggesting fields in JQL like cf[12345]:

Screen Shot 2022-02-22 at 11.19.55 pm.png

So for example, if "Start Date" was cf[12345] you could have:

issueFunction in dateCompare("", "created > cf[12345]")

Please give it a try and let me know how it goes. I hope it helps.

Cheers,

Carlos 

Nadine Schuett February 25, 2022

Hello @carlosughini

Thanks a lot for the suggestion.

I am afraid it does not work for me though

 Message: Field name: cf[16300] not found or not a date or datetime

The ID is correct so it must either be the format or it's generally not possible to use cf IDs here.

carlosughini
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 28, 2022

Hey @Nadine Schuett ,

I'm afraid we are facing some type of bug or it is not able to search by id, unfortunately.

I've performed some tests on my side, even using "customfield_id" which is a Groovy code in the JQL, however, with no success.

I strongly recommend a support ticket here so Adaptavist can help you with this issue.

Please give it a try and let me know if you have any issues.

Regards,

Carlos

Nadine Schuett March 3, 2022

Hello @carlosughini 

I contacted Adaptavist support and they told me that the dateCompare JQL function does not support search using a custom field ID. 

However, I got the advice to use the even more powerful expression function and that works well:

issueFunction in expression("", "created > customfield_16300")

Thanks for your help and have a great day

Nadine

Like # people like this

Suggest an answer

Log in or Sign up to answer