How to get the value of calculated custom field in SQL

Hello All,

 

I am wondering if anyone knows how to query the jira db to get the calculated custom field. I am writing the query and is stucked on this : Below the extract of the query.

SELECT  CAST(I.ID AS NUMERIC) AS ISSUE_ID,
        CONCAT (p.pkey, '-', I.issuenum) as IssueID,
        I.SUMMARY,
        PRJ_MAN.StringValue AS PRJ_MANAGER,
        CUST.CUSTOMVALUE AS CUSTOMER,
        UNIT.CUSTOMVALUE AS BUSINESS_UNIT,
        ISTATUS.PNAME AS STATUS,
        ITYPE.PNAME AS TYPE,
        CAST(ROUND(SUM(AE_PM.WORKLOAD) / 8, 2) AS NUMERIC) AS SKILL_ESTIMATED,
        I.TIMEESTIMATE/28800 AS ISSUE_ESTIMATED,
        DOM_DEV.CUSTOMVALUE as TEAM,
        AE_PM.SKILL AS SKILL_CODE,
        SKILL.TITLE AS SKILL
    
       
  FROM JIRAISSUE I
  LEFT OUTER JOIN PROJECT P ON I.PROJECT=P.ID
  LEFT OUTER JOIN AO_D9132D_ASSIGNMENT_EXT AE_PM ON  I.ID=AE_PM.ISSUE
  LEFT OUTER JOIN AO_82B313_SKILL SKILL ON CAST(SKILL.ID AS NVARCHAR)=AE_PM.SKILL
  LEFT OUTER JOIN ISSUESTATUS ISTATUS ON I.ISSUESTATUS=ISTATUS.ID
  LEFT OUTER JOIN ISSUETYPE ITYPE ON I.ISSUETYPE=ITYPE.ID
  LEFT OUTER JOIN (SELECT cfv.issue, cfo.customvalue, cf.cfname
                   FROM CustomFieldValue cfv
                   LEFT OUTER JOIN CustomField CF on CF.Id = CFV.CustomField
                   LEFT OUTER JOIN CustomFieldOption CFO on CF.Id  = CFO.CustomField
                   where cf.CFName Like 'Customer%'
                   And CAST(CFO.Id AS Varchar) = CFV.StringValue ) CUST ON CUST.ISSUE=I.ID
  LEFT OUTER JOIN (SELECT cfv.issue, cfo.customvalue, cf.cfname
                   FROM CustomFieldValue cfv
                   LEFT OUTER JOIN CustomField CF on CF.Id = CFV.CustomField
                   LEFT OUTER JOIN CustomFieldOption CFO on CF.Id  = CFO.CustomField
                   where cf.CFName Like '%Unit%'
                   And CAST(CFO.Id AS Varchar) = CFV.StringValue ) Unit ON Unit.ISSUE=I.ID
 LEFT OUTER JOIN  (SELECT cfv.issue,  cf.cfname,CFV.StringValue
                   FROM CustomFieldValue cfv
                   LEFT OUTER JOIN CustomField CF on CF.Id = CFV.CustomField
                   where cf.CFName='Project Manager' ) PRJ_MAN ON PRJ_MAN.ISSUE=I.ID
LEFT OUTER JOIN    (SELECT cfv.issue, cfo.customvalue, cf.cfname
                   FROM CustomFieldValue cfv
                   LEFT OUTER JOIN CustomField CF on CF.Id = CFV.CustomField
                   LEFT OUTER JOIN CustomFieldOption CFO on CF.Id  = CFO.CustomField
                   where cf.CFName='Domain lead'
                   And CAST(CFO.Id AS Varchar) = CFV.StringValue ) DOM_DEV ON DOM_DEV.ISSUE=I.ID
  WHERE p.pname='XXXX'
  GROUP BY
  I.ID,
  AE_PM.SKILL,
  I.SUMMARY,
  I.TIMEESTIMATE,
  p.pkey,
  I.issuenum,
  SKILL.TITLE,
  CUST.CUSTOMVALUE,
  Unit.CUSTOMVALUE,
  ISTATUS.PNAME,
  ITYPE.PNAME,
  PRJ_MAN.StringValue,
  DOM_DEV.CUSTOMVALUE

Any help or guide will be apprecaited.

 

Thank you in advance,

Karim

1 answer

0 votes

SQL is the single worst way to get any information out of an Atlassian application. 

Calculated fields are not held in the database at all.  So you can't get them with SQL, you need to duplicate all the logic behind them.

I'd suggest thinking of a sane way to do your reporting, rather than digging in the database.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,897 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot