Changes between Version 1 and Version 2 of TracTicketsCustomFields
- Timestamp:
- 06/08/2008 14:15:50 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracTicketsCustomFields
v1 v2 17 17 * label: Descriptive label. 18 18 * value: Default value. 19 * order: Sort order placement. (Determines relative placement in forms .)19 * order: Sort order placement. (Determines relative placement in forms with respect to other custom fields.) 20 20 * '''checkbox''': A boolean value check box. 21 21 * label: Descriptive label. … … 25 25 * label: Descriptive label. 26 26 * options: List of values, separated by '''|''' (vertical pipe). 27 * value: Default value ( Item #, starting at 0).27 * value: Default value (one of the values from options). 28 28 * order: Sort order placement. 29 29 * '''radio''': Radio buttons. Essentially the same as '''select'''. 30 30 * label: Descriptive label. 31 31 * options: List of values, separated by '''|''' (vertical pipe). 32 * value: Default value ( Item #, starting at 0).32 * value: Default value (one of the values from options). 33 33 * order: Sort order placement. 34 34 * '''textarea''': Multi-line text area. … … 57 57 test_four.label = My selectbox 58 58 test_four.options = one|two|third option|four 59 test_four.value = 259 test_four.value = two 60 60 61 61 test_five = radio 62 62 test_five.label = Radio buttons are fun 63 63 test_five.options = uno|dos|tres|cuatro|cinco 64 test_five.value = 164 test_five.value = dos 65 65 66 66 test_six = textarea … … 75 75 === Reports Involving Custom Fields === 76 76 77 The SQL required for TracReports to include custom ticket fields is relatively hard to get right. You need a `JOIN` with the `ticket_custom` field for every custom field that should be involved.77 Custom ticket fields are stored in the `ticket_custom` table, not in the `ticket` table. So to display the values from custom fields in a report, you will need a join on the 2 tables. Let's use an example with a custom ticket field called `progress`. 78 78 79 The following example includes a custom ticket field named `progress` in the report: 79 {{{ 80 #!sql 81 SELECT p.value AS __color__, 82 id AS ticket, summary, owner, c.value AS progress 83 FROM ticket t, enum p, ticket_custom c 84 WHERE status IN ('assigned') AND t.id = c.ticket AND c.name = 'progress' 85 AND p.name = t.priority AND p.type = 'priority' 86 ORDER BY p.value 87 }}} 88 '''Note''' that this will only show tickets that have progress set in them, which is '''not the same as showing all tickets'''. If you created this custom ticket field ''after'' you have already created some tickets, they will not have that field defined, and thus they will never show up on this ticket query. If you go back and modify those tickets, the field will be defined, and they will appear in the query. If that's all you want, you're set. 89 90 However, if you want to show all ticket entries (with progress defined and without), you need to use a `JOIN` for every custom field that is in the query. 80 91 {{{ 81 92 #!sql … … 96 107 Note in particular the `LEFT OUTER JOIN` statement here. 97 108 109 === Updating the database === 110 111 As noted above, any tickets created before a custom field has been defined will not have a value for that field. Here's a bit of SQL (tested with SQLite) that you can run directly on the Trac database to set an initial value for custom ticket fields. Inserts the default value of 'None' into a custom field called 'request_source' for all tickets that have no existing value: 112 113 {{{ 114 #!sql 115 INSERT INTO ticket_custom 116 (ticket, name, value) 117 SELECT 118 id AS ticket, 119 'request_source' AS name, 120 'None' AS value 121 FROM ticket 122 WHERE id NOT IN ( 123 SELECT ticket FROM ticket_custom 124 ); 125 }}} 126 127 If you added multiple custom fields at different points in time, you should be more specific in the subquery on table {{{ticket}}} by adding the exact custom field name to the query: 128 129 {{{ 130 #!sql 131 INSERT INTO ticket_custom 132 (ticket, name, value) 133 SELECT 134 id AS ticket, 135 'request_source' AS name, 136 'None' AS value 137 FROM ticket 138 WHERE id NOT IN ( 139 SELECT ticket FROM ticket_custom WHERE name = 'request_source' 140 ); 141 }}} 142 98 143 ---- 99 144 See also: TracTickets, TracIni