Global Custom Fields
Posted: 28 Sep 2011, 11:34
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!
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!