Bugzilla::Field - a particular piece of information about bugs and useful routines for form field manipulation


  use Bugzilla;
  use Data::Dumper;

  # Display information about all fields.
  print Dumper(Bugzilla->get_fields());

  # Display information about non-obsolete custom fields.
  print Dumper(Bugzilla->active_custom_fields);

  use Bugzilla::Field;

  # Display information about non-obsolete custom fields.
  # Bugzilla->get_fields() is a wrapper around Bugzilla::Field->match(),
  # so both methods take the same arguments.
  print Dumper(Bugzilla::Field->match({ obsolete => 0, custom => 1 }));

  # Create or update a custom field or field definition.
  my $field = Bugzilla::Field->create(
    {name => 'cf_silly', description => 'Silly', custom => 1});

  # Instantiate a Field object for an existing field.
  my $field = new Bugzilla::Field({name => 'qacontact_accessible'});
  if ($field->obsolete) {
      print $field->description . " is obsolete\n";

  # Validation Routines
  check_field($name, $value, \@legal_values, $no_warn);
  $fieldid = get_field_id($fieldname);


Field.pm defines field objects, which represent the particular pieces of information that Bugzilla stores about bugs.

This package also provides functions for dealing with CGI form fields.

Bugzilla::Field is an implementation of Bugzilla::Object, and so provides all of the methods available in Bugzilla::Object, in addition to what is documented here.

Instance Properties


the name of the field in the database; begins with "cf_" if field is a custom field, but test the value of the boolean "custom" property to determine if a given field is a custom field;


a short string describing the field; displayed to Bugzilla users in several places within Bugzilla's UI, f.e. as the form field label on the "show bug" page;


an integer specifying the kind of field this is; values correspond to the FIELD_TYPE_* constants in Constants.pm


a boolean specifying whether or not the field is a custom field; if true, field name should start "cf_", but use this property to determine which fields are custom fields;


a boolean specifying whether or not the field is displayed in bugmail for newly-created bugs;


an integer specifying the sortkey of the field.


a boolean specifying whether or not the field is obsolete;


A boolean specifying whether or not this field should appear on enter_bug.cgi


A reference to an array with valid active values for this field.

Instance Mutators

These set the particular field that they are named after.

They take a single value--the new value for that field.

They will throw an error if you try to set the values to something invalid.


Instance Method


Attempts to remove the passed in field from the database. Deleting a field is only successful if the field is obsolete and there are no values specified (or EVER specified) for the field.

Class Methods


Just like "create" in Bugzilla::Object. Takes the following parameters:

name Required - The name of the field.
description Required - The field label to display in the UI.
mailhead - boolean - Whether this field appears at the top of the bugmail for a newly-filed bug. Defaults to 0.
custom - boolean - True if this is a Custom Field. The field will be added to the bugs table if it does not exist. Defaults to 0.
sortkey - integer - The sortkey of the field. Defaults to 0.
enter_bug - boolean - Whether this field is editable on the bug creation form. Defaults to 0.

obsolete - boolean - Whether this field is obsolete. Defaults to 0.


Description: returns all the legal values for a field that has a list of legal values, like rep_platform or resolution. The table where these values are stored must at least have the following columns: value, isactive, sortkey.

Params: $field - Name of the table where valid values are.

Returns: a reference to a list of valid values.


Description: Populates the fielddefs table during an installation or upgrade.

Params: none

Returns: nothing

Data Validation

check_field($name, $value, \@legal_values, $no_warn)

Description: Makes sure the field $name is defined and its $value is non empty. If @legal_values is defined, this routine checks whether its value is one of the legal values associated with this field, else it checks against the default valid values for this field obtained by get_legal_field_values($name). If the test is successful, the function returns 1. If the test fails, an error is thrown (by default), unless $no_warn is true, in which case the function returns 0.

Params: $name - the field name $value - the field value @legal_values - (optional) list of legal values $no_warn - (optional) do not throw an error if true

Returns: 1 on success; 0 on failure if $no_warn is true (else an error is thrown).


Description: Returns the ID of the specified field name and throws an error if this field does not exist.

Params: $name - a field name

Returns: the corresponding field ID or an error if the field name does not exist.