Edgewall Software
Modify

Opened 20 years ago

Closed 18 years ago

#1094 closed defect (fixed)

Document usage of custom ticket fields in reports

Reported by: bryan@… Owned by: daniel
Priority: low Milestone: 0.11
Component: report system Version: 0.8
Severity: minor Keywords: documentation
Cc: bryan@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

TracTicketsCustomFields is great. However, on 0.8 I don't seem to be able to include the custom fields as columns in my report? Is this a limitation of Trac 0.8 or a limitation of my SQL-fu?

Attachments (0)

Change History (6)

comment:1 by bryan@…, 20 years ago

further info. System is Debian/stable with python 2.2.1, no mod_python. trac.ini contains:

[ticket-custom]
hours_est = text
hours_est.label = <i>Addtional</i> hours to complete
hours_est.value = 1
hours_spent = text
hours_spent.width = 5
hours_spent.label = Hours spent

And my test report contains:

SELECT p.value AS __color__,
   id AS ticket, summary, component, severity, owner, hours_est
  FROM ticket t, enum p
  WHERE status IN ('assigned') 
AND p.name = t.priority AND p.type = 'priority'
  ORDER BY p.value

The report fails with the message

Report failed: no such column: hours_est

comment:2 by eric.brown@…, 20 years ago

You're just using the wrong SQL. I've gotten it to work in trac 0.8. I think you need the following SQL:

SELECT p.value AS __color__,
   id AS ticket, summary, component, severity, owner, c.value AS hours_est
  FROM ticket t, enum p, custom_ticket c
  WHERE status IN ('assigned') AND t.id = c.ticket AND c.name = 'hours_est'
AND p.name = t.priority AND p.type = 'priority'
  ORDER BY p.value

Now, this will only show tickets that have hours_est set in them. If that's all you want, you're set.

Or, if you want to show entries with hours_est and without:

   ...
   (CASE WHEN c.value IS NULL THEN '' ELSE c.value END) AS hours_est
  FROM ticket t LEFT OUTER JOIN ticket_custom c ON t.id = c.ticket AND c.name = 'hours_est'
     JOIN enum p ON p.name = t.priority AND p.type='priority'
   ...

Presumably if you want to show multiple custom columns, you can do additional LEFT OUTER JOINs and simply alias the ticket_custom table differently. I haven't tried that though.

I don't think this is a bug. Let me know if I mistyped any of the SQL above and you can't find the mistype. I use a custom column for the exact same purpuse you do and my query works fine. In fact, just in case my SQL above is wrong, here's the query I use on my system (my custom field is called duration):

SELECT p.value AS __color__,
   owner AS __group__,
   id AS ticket, summary, component, milestone, severity, time AS created,
   changetime AS _changetime, description AS _description,
   reporter AS _reporter,
   (CASE WHEN c.value IS NULL THEN '' ELSE c.value END) AS days
  FROM ticket t LEFT OUTER JOIN ticket_custom c ON t.id = c.ticket AND c.name = 'duration'
     JOIN enum p ON p.name = t.priority AND p.type='priority'
--  FROM ticket t,enum p
  WHERE status IN ('new', 'assigned', 'reopened') 
-- AND p.name=t.priority AND p.type='priority'
  ORDER BY owner, milestone, p.value, severity, time

comment:3 by anonymous, 20 years ago

Priority: normallow
Severity: normalminor

Ah, thanks. I bow to your greater SQL-fu. Knowing to pull from table custom_ticket is a huge help by itself! Being a newbie on linux and just a scratcher when it comes to SQL, I was stumbling around in the dark. Others with similar issues might be helped by taking a look at the database schema.

I suspect it would be good if someone documented an example or two on the TracTicketsCustomFields page or in the sample reports that come with Trac?

comment:4 by Christopher Lenz, 20 years ago

Keywords: documentation added
Summary: Custom fields not usable in reports?Document usage of custom ticket fields in reports

comment:5 by jim@…, 20 years ago

I'm adding another example to the wiki, referenced off TracReports

in reply to:  2 comment:6 by sid@…, 18 years ago

Milestone: 0.11
Resolution: fixed
Status: newclosed

Okay, I added some of the comments from this ticket into the page TracTicketsCustomFields as well. Looks good guys.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain daniel.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from daniel to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.