how can I best write a query to join jiraissue and customfieldvalue table

We have few customfield defined for jira issues. Users want to search based on the customfield value which is a text box.

in order to do that we have written a plugin using java which does that.

Here is a sample SQL that I have written to get the search result joining jiraissue table and customfieldvalue table.

I need a better way of doing it.

/**********************************************************************************************************************/

select

distinct(ji.pkey), ji.reporter,ji.assignee, ji.summary

from

jiraissue ji,

(select

issue,

MAX(CASE WHEN CUSTOMFIELD='11002' THEN STRINGVALUE END) AS customer_code,

MAX(CASE WHEN CUSTOMFIELD='12111' THEN STRINGVALUE END) AS fname,


from

customfieldvalue

group by issue

) as condition_value

where

ji.id=condition_value.issue and

ji.PROJECT = 11400 and

condition_value.customer_code='1850' and

condition_value.fname='Test'

/**********************************************************************************************************************/

1 answer

1 accepted

This widget could not be displayed.

That looks rather complex to me, but also unnecessary I really do have to ask why you are doing it this way?

You say

>Users want to search based on the customfield value which is a text box

So let's say you've got a field called "my text box" and you want to look for the word "Test", in project XX. Your JQL is

project = XX and "my text box" ~ "Test"

Could you explain the requirement and why JQL won't do it for you?

we are using the plugin to do this job .... is there a api that we can use to get the result

The built-in filter system runs JQL, so I don't understand why you are even bothering with a plugin. That's why I asked why you are bothering - you have not described your plugin doing anything Jira cannot already do, off-the-shelf. Is there some reason you are doing this with a plugin?

To answer the API question, yes, you can. In fact, it's really a bad idea to use SQL - the whole reason JQL is there is that it's a much better way to search than raw SQL. Have a look at https://confluence.atlassian.com/display/JIRA/__Searching+in+JIRA

An example of why you should use JQL - if you want to search custom field data, in SQL, you need to join jiraissue, customfield, customfieldvalue, and possibly customfieldoption and then go through the returned data. If you want to search in JQL, you say "field x ~ search"

Thanks for the info Nic.

We are trying to use JIRA as call center app, similar to remedy. So we have built some custom tables to store some customer, consumer data ... this we are adding it as custom field in jira. We have around 5 fields that is part of custom field. Integrating this which needs a custom search and jira search integration.

I am sure these custom field can be optional in JQL and it still gets us the search result .... ?

The built-in filter system runs JQL, so I don't understand why you are even bothering with a plugin. That's why I asked why you are bothering - you have not described your plugin doing anything Jira cannot already do, off-the-shelf. Is there some reason you are doing this with a plugin?

To answer the API question, yes, you can. In fact, it's really a bad idea to use SQL - the whole reason JQL is there is that it's a much better way to search than raw SQL. Have a look at https://confluence.atlassian.com/display/JIRA/__Searching+in+JIRA

An example of why you should use JQL - if you want to search custom field data, in SQL, you need to join jiraissue, customfield, customfieldvalue, and possibly customfieldoption and then go through the returned data. If you want to search in JQL, you say "field x ~ search"

By the way, I'm not saying that your plugin is wrong - it's just that I don't understand what it's trying to achieve that Jir

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

176 views 18 7
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you