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

Umesh Rangappa November 27, 2012

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

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 27, 2012

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?

Umesh Rangappa November 27, 2012

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 27, 2012

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"

Umesh Rangappa November 27, 2012

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 27, 2012

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
TAGS
AUG Leaders

Atlassian Community Events