Changes between Version 1 and Version 2 of TracTicketsCustomFields


Ignore:
Timestamp:
11/06/17 14:13:24 (5 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracTicketsCustomFields

    v1 v2  
    1717   * label: Descriptive label. 
    1818   * 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   * format: Either `plain` for plain text or `wiki` to interpret the content as WikiFormatting. (''since 0.11.3'') 
    2021 * '''checkbox''': A boolean value check box. 
    2122   * label: Descriptive label. 
     
    2324   * order: Sort order placement. 
    2425 * '''select''': Drop-down select box. Uses a list of values. 
     26   * label: Descriptive label. 
    2527   * options: List of values, separated by '''|''' (vertical pipe). 
    26    * value: Default value (Item #, starting at 0). 
     28   * value: Default value (one of the values from options). 
    2729   * order: Sort order placement. 
    2830 * '''radio''': Radio buttons. Essentially the same as '''select'''. 
    2931   * label: Descriptive label. 
    3032   * options: List of values, separated by '''|''' (vertical pipe). 
    31    * value: Default value (Item #, starting at 0). 
     33   * value: Default value (one of the values from options). 
    3234   * order: Sort order placement. 
    3335 * '''textarea''': Multi-line text area. 
     
    3739   * rows: Height in lines. 
    3840   * order: Sort order placement. 
     41   * format: Either `plain` for plain text or `wiki` to interpret the content as WikiFormatting. (''since 0.11.3'') 
    3942 
    4043=== Sample Config === 
     
    4750test_two = text 
    4851test_two.label = Another text-box 
    49 test_two.value = Just a default value 
     52test_two.value = Default [mailto:[email protected] owner] 
     53test_two.format = wiki 
    5054 
    5155test_three = checkbox 
     
    5660test_four.label = My selectbox 
    5761test_four.options = one|two|third option|four 
    58 test_four.value = 2 
     62test_four.value = two 
    5963 
    6064test_five = radio 
    6165test_five.label = Radio buttons are fun 
    6266test_five.options = uno|dos|tres|cuatro|cinco 
    63 test_five.value = 1 
     67test_five.value = dos 
    6468 
    6569test_six = textarea 
     
    7074}}} 
    7175 
    72 ''Note: To make an entering an option for a `select` type field optional, specify a leading `|` in the `fieldname.options` option.'' 
     76''Note: To make entering an option for a `select` type field optional, specify a leading `|` in the `fieldname.options` option.'' 
    7377 
    7478=== Reports Involving Custom Fields === 
    7579 
    76 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. 
     80Custom 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`. 
    7781 
    78 The following example includes a custom ticket field named `progress` in the report: 
     82{{{ 
     83#!sql 
     84SELECT p.value AS __color__, 
     85   id AS ticket, summary, owner, c.value AS progress 
     86  FROM ticket t, enum p, ticket_custom c 
     87  WHERE status IN ('assigned') AND t.id = c.ticket AND c.name = 'progress' 
     88AND p.name = t.priority AND p.type = 'priority' 
     89  ORDER BY p.value 
     90}}} 
     91'''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. 
     92 
     93However, 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. 
    7994{{{ 
    8095#!sql 
     
    95110Note in particular the `LEFT OUTER JOIN` statement here. 
    96111 
     112=== Updating the database === 
     113 
     114As 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: 
     115 
     116{{{ 
     117#!sql 
     118INSERT INTO ticket_custom 
     119   (ticket, name, value) 
     120   SELECT  
     121      id AS ticket, 
     122      'request_source' AS name, 
     123      'None' AS value 
     124   FROM ticket  
     125   WHERE id NOT IN ( 
     126      SELECT ticket FROM ticket_custom 
     127   ); 
     128}}} 
     129 
     130If 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: 
     131 
     132{{{ 
     133#!sql 
     134INSERT INTO ticket_custom 
     135   (ticket, name, value) 
     136   SELECT  
     137      id AS ticket, 
     138      'request_source' AS name, 
     139      'None' AS value 
     140   FROM ticket  
     141   WHERE id NOT IN ( 
     142      SELECT ticket FROM ticket_custom WHERE name = 'request_source' 
     143   ); 
     144}}} 
     145 
    97146---- 
    98147See also: TracTickets, TracIni