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 vote

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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

614 views 3 11
Read article

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