need help with inserting default values in custom fields

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
omeslo
Posts: 16
Joined: 23 Apr 2007, 14:42

need help with inserting default values in custom fields

Post by omeslo »

I added a custom field to a long running project. (5000+ bugs) and I was wondering if there is a way to put a default value in this custom field for all previously reported bugs.
These fields are now empty, so they cannot be used for filtering.
I do have access to the database, and have been fiddling around with some queries, but i'm not fluent in mysql so I coulnd't figure it out.

Any help would be greatly appreciated.

(mantis v1.0.6)
Tinjaw
Posts: 24
Joined: 06 Oct 2005, 16:23
Location: Kansas City, MO
Contact:

Re: need help with inserting default values in custom fields

Post by Tinjaw »

Look at custom_field_table and find the id of the custom field. Do a sub select on bug_table and find all bugs for that project and insert a row into custom_field_string_table for each one.
omeslo
Posts: 16
Joined: 23 Apr 2007, 14:42

Re: need help with inserting default values in custom fields

Post by omeslo »

Tinjaw wrote:Look at custom_field_table and find the id of the custom field. Do a sub select on bug_table and find all bugs for that project and insert a row into custom_field_string_table for each one.
Thx for your reply, Tinjaw.. figured that much out myself but it'll be too much trouble to do it manually. I wrote a query to do this for me.. not really fluent in SQL so if anyone spots an error, please let me know.

first we gotta find the field id for the custom field we are looking for:
SELECT id FROM `mantis_custom_field_table` WHERE name = 'fieldname' (where 'fieldname' is the name of the custom field)

and insert the rows with the following query:

INSERT INTO mantis_custom_field_string_table (field_id, bug_id, value)
SELECT 26, mbt.id , 'def_value'
FROM `mantis_bug_table` AS mbt
WHERE NOT EXISTS
(SELECT * FROM mantis_custom_field_string_table AS mcfst
WHERE mbt.id = mcfst.bug_id
AND mcfst.field_id = 26)

where '26' is the id we found with the first query, and 'def_value' is the desired default value.

Both queries can easily be integrated into one, and maybe it would be a nice feature to add a checkbox with a textfield when adding a custom field in Mantis, so the user has the option to fill all fields of previous reported bugs with any default value when checked.
Post Reply