Global Custom Fields

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
leonardo.m

Global Custom Fields

Post by leonardo.m »

Hi guys,

I would like to share a simple solution to create global custom fields, in other words, custom fields created for all projects automatically.

This is a mysql trigger activated AFTER a project creation.

** NOTES)
A) THE CODE IS SAFE. I USE IT MYSELF.
B) USE IT ON YOUR OWN RISK. I AM NOT RESPONSIBLE FOR POSSIBLE DATA LOST.
C) IF YOU HAVE SOME IMPROVEMENT, PLEASE POST IT !

1) Creating the custom fields
Mantis -> Manage -> Manage custom fields -> New custom field

2) Log in into mysql
mysql -h 'machine' -u 'user' -p

3) Select custom fields information
use 'your_mantis_db'; (in my case: use bugtracker;
SELECT * FROM mantis_custom_field_table;
Please copy the ID of the custom fields which you would like to make "global"
Example: TEST_FIELD = ID: 2

3) Creating the trigger
use bugtracker;
delimiter $$
CREATE TRIGGER global_custom_fields AFTER INSERT ON mantis_project_table
FOR EACH ROW BEGIN
DECLARE _last_id_inserted int(10) unsigned;
SELECT MAX(id) INTO _last_id_inserted FROM mantis_project_table;
INSERT INTO mantis_custom_field_project_table (field_id, project_id,sequence) VALUES (**CUSTOM_FIELD_ID**,_last_id_inserted,**CUSTOM_FIELD_PRIORITY**);
INSERT INTO mantis_custom_field_project_table (field_id, project_id,sequence) VALUES (**CUSTOM_FIELD_ID**,_last_id_inserted,**CUSTOM_FIELD_PRIORITY**);
END $$

Please note that you must replace the **CUSTOM_FIELD_ID** and **CUSTOM_FIELD_PRIORITY** by the respective values.
Example: INSERT INTO mantis_custom_field_project_table (field_id, project_id,sequence) VALUES (2,_last_id_inserted,100);

You can insert as many rows as you want.

4) Drop the trigger
IF YOU DON'T WANT TO USE THIS SOLUTION ANYMORE YOU CAN DELETE IT THROUGH THE FOLLOWING LINES:

use bugtracker;
DROP TRIGGER global_custom_fields;

5) END

Thank you!
I hope that it helps!
atrol
Site Admin
Posts: 8536
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Global Custom Fields

Post by atrol »

Thanks for sharing your solution.
I hope that everybody who wants to use it is also reading your notes and warnings ;-)
Please use Search before posting and read the Manual
speedyrazor
Posts: 9
Joined: 20 Mar 2010, 13:49

Re: Global Custom Fields

Post by speedyrazor »

Hi, I wanted to ask a question about CUSTOM_FIELD_ID and CUSTOM_FIELD_PRIORITY.

1. I am unsure of what this applies to under number 2, "Please copy the ID of the custom fields which you would like to make "global"
Example: TEST_FIELD = ID: 2"

2. CUSTOM_FIELD_ID comes from the custom field number? so the first custom field I create will be 1, 2nd will be 2 and so on?

3. I am not sure about CUSTOM_FIELD_PRIORITY, in your example you use the value 100, not sure what this value entails.

Kind regards.
Post Reply