Change workflow based on selected category
Moderators: Developer, Contributor
Change workflow based on selected category
Hi,
I would like to change the Workflow based on the selected Category name of the report.
Could someone tell me if this is possible and which steps I have to follow, to get it to work?
Best regards,
Mathias
I would like to change the Workflow based on the selected Category name of the report.
Could someone tell me if this is possible and which steps I have to follow, to get it to work?
Best regards,
Mathias
Re: Change workflow based on selected category
By that I mean to create custom workflows transitions based on the selected category name of the report.
By now it is only possible to add custom workflow transitions to projects, but I would like to add custom workflow transitions to each category.
Maybe this could be done with a switch case operation.
I have no idea how to do this customization, so I hoped, someone of the forum coud help me.
By now it is only possible to add custom workflow transitions to projects, but I would like to add custom workflow transitions to each category.
Maybe this could be done with a switch case operation.
I have no idea how to do this customization, so I hoped, someone of the forum coud help me.
Re: Change workflow based on selected category
Could at least someone tell me if this is possible to achive?
So far I've edited the bug_api.php and added a new function "bug_get_category_id(bug_id)" to get the category ID of the currently opened bug.
Then I tried to include the bug_api.php and bugnote_view.php in the config_inc.php and open my function (bug_get_category_id(bug_id)) to retrieve the category_ID with the bug_id as parameter given from the bugnote_view.php.
Then based on the returned category ID of my function, I wanted to set my custom workflow transitions with an if statement.
The problem is, that I get errors like "Fatal error: Call to undefined function lang_push() in /var/www/mantisbt/core/error_api.php on line 82".
Is this even the right way to achieve my goal?
Best regards,
Mathias
So far I've edited the bug_api.php and added a new function "bug_get_category_id(bug_id)" to get the category ID of the currently opened bug.
Then I tried to include the bug_api.php and bugnote_view.php in the config_inc.php and open my function (bug_get_category_id(bug_id)) to retrieve the category_ID with the bug_id as parameter given from the bugnote_view.php.
Then based on the returned category ID of my function, I wanted to set my custom workflow transitions with an if statement.
The problem is, that I get errors like "Fatal error: Call to undefined function lang_push() in /var/www/mantisbt/core/error_api.php on line 82".
Is this even the right way to achieve my goal?
Best regards,
Mathias
Re: Change workflow based on selected category
Seems like I solved it.
Re: Change workflow based on selected category
hey mathiasH.
Im interested on your solution, could you expand a little on it? I have a few cases that need a special workflow acording to the category or custom_fields and you hitted the nail with this.
Can u elaborate on your resolution?
Thanks!
Im interested on your solution, could you expand a little on it? I have a few cases that need a special workflow acording to the category or custom_fields and you hitted the nail with this.
Can u elaborate on your resolution?
Thanks!
Re: Change workflow based on selected category
Hi favioagg,
I just want to say, that I don't know for sure, if my solution is working properly. For me, it does right now. I will post my solution here. Maybe some devs of Mantis will see it and tell me, if I broke my Mantis with that or can give me some tips to make my solution better.
Quick summary of what I wanted to achive. I wanted to define more Workflows than one in the config_inc.php. Mantis should then choose the right workflow based on the category of the bug and the access role of the currently logged in user (Reporter, Manager, Administrator...). The addition of the access role helps to define workflows for reporter and managers (or other roles) of a project. The reporter can close a bug, but can't reopen it. The manager has his own workflow and can reopen the bug anytime.
So here is what I did.
First of all I created a new api file "NEWFILE_api.php" in the core directory, for new funtcions. One function I made was "bug_get_category_ID ($bug_id). This funtion gets the Category ID of the currently opened Bug from the database.
Then I added my different workflows in the config_inc.php. For example I named them like
And a default one
The first two workflows are defined for the category with the name "test". As you can see, the name of the variable has a pattern. It is "$g_status_enum_workflow_categoryname_Userrole". If you don't need a specific workflow for the Userrole, then just leave it out. In my case, I need both workflows.
The default workflow is only needed, if no other workflow is defined for the current category.
Then I edited the function get_status_option_list() in the file core/print_api.php. I added a new Parameter $bug_id, because now I will call the function "bug_get_category_ID($bug_ID)" within get status_option_list().
Then I've edited the first lines of the function get_status_option_list. This code checks, if there is a defined workflow with the categoryname of the currently opened bug and userrole of the currently logged in user. If not, check if there is a workflow only for the categoryname. And if not, just take the default workflow.
You also have to put a require_once in print_api.php for your new api file.
Because we've added a new parameter to the function get_status_option_list() you have to add the parameter to every file, where the function is called.
Add the parameter to:
bug_update_advanced_page.php
bug_report_page.php (add to function print_status_option_list())
html_api.php
print_api.php
Now you have to disable the Exception Output for the workflow config. Usually you have one workflow defined in the config_inc.php file. If Mantis does not find it, it will display an error message "Application warning 100". Because of the new if statements, that loads different workflows, it could happen, that the error is displayed, despite the fact, that everything is alright. This happens because mantis now searches for different workflows till it finds the right one or jumps to the default one. To disable that error message you have to go to core/config_api.php and comment out the line "trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, WARNING );".
This is what I did. Like I said, I don't know if this is a good solution. I hope I could explain it good enough and I didn't forget anything.
Note, that you have to put all these changes in back in mantis, after you updated to a new version.
Best regards,
Mathias
I just want to say, that I don't know for sure, if my solution is working properly. For me, it does right now. I will post my solution here. Maybe some devs of Mantis will see it and tell me, if I broke my Mantis with that or can give me some tips to make my solution better.
Quick summary of what I wanted to achive. I wanted to define more Workflows than one in the config_inc.php. Mantis should then choose the right workflow based on the category of the bug and the access role of the currently logged in user (Reporter, Manager, Administrator...). The addition of the access role helps to define workflows for reporter and managers (or other roles) of a project. The reporter can close a bug, but can't reopen it. The manager has his own workflow and can reopen the bug anytime.
So here is what I did.
First of all I created a new api file "NEWFILE_api.php" in the core directory, for new funtcions. One function I made was "bug_get_category_ID ($bug_id). This funtion gets the Category ID of the currently opened Bug from the database.
Code: Select all
<?php
/** Get Category_ID of currently opened BUG
* @param int p_bug_id
*/
function bug_get_category_ID( $p_bug_id ) {
$c_bug_id = db_prepare_int( $p_bug_id );
$t_bugnote_table = db_get_table( 'mantis_bug_table' );
$query = "SELECT category_id
FROM $t_bugnote_table
WHERE bug_text_id=" . $p_bug_id . "";
$result = db_query_bound( $query, Array( $c_bug_id ), 1 );
$row = db_result( $result );
if( false === $row ) {
return false;
} else {
return $row;
}
}
?>
Code: Select all
$g_status_enum_workflow_test_Administrator = array (
10 => '20:in Bearbeitung',
20 => '40:Test,30:zurückgestellt,50:Test Kunde,80:Rechnungsstellung,90:geschlossen',
30 => '20:in Bearbeitung',
40 => '50:Test Kunde,20:in Bearbeitung,30:zurückgestellt,90:geschlossen',
50 => '80:Rechnungsstellung,20:in Bearbeitung,40:Test',
80 => '90:geschlossen',
90 => '20:in Bearbeitung,10:geöffnet',
);
Code: Select all
$g_status_enum_workflow_test = array (
10 => '20:in Bearbeitung',
20 => '90:geschlossen,10:geöffnet',
90 => '20:in Bearbeitung',
);
Code: Select all
$g_status_enum_workflow_default = array (
10 => '20:in Bearbeitung',
20 => '40:Test,30:zurückgestellt,50:Test Kunde,80:Rechnungsstellung,90:geschlossen',
30 => '20:in Bearbeitung',
40 => '50:Test Kunde,20:in Bearbeitung,30:zurückgestellt,10:geöffnet',
50 => '80:Rechnungsstellung,20:in Bearbeitung,40:Test',
80 => '90:geschlossen',
90 => '20:in Bearbeitung,10:geöffnet',
);
The default workflow is only needed, if no other workflow is defined for the current category.
Then I edited the function get_status_option_list() in the file core/print_api.php. I added a new Parameter $bug_id, because now I will call the function "bug_get_category_ID($bug_ID)" within get status_option_list().
Code: Select all
function get_status_option_list( $p_user_auth = 0, $p_current_value = 0, $p_show_current = true, $p_add_close = false, $p_project_id = ALL_PROJECTS, $bug_id ) {
Code: Select all
function get_status_option_list( $p_user_auth = 0, $p_current_value = 0, $p_show_current = true, $p_add_close = false, $p_project_id = ALL_PROJECTS, $bug_id ) {
$t_config_var_value = config_get( 'status_enum_string', null, null, $p_project_id );
if (config_get( 'status_enum_workflow' . _ . category_get_name( bug_get_category_ID( $bug_id )) . _ . get_enum_element( 'access_levels', current_user_get_access_level() ), null, null, $p_project_id ) != null) {
$t_enum_workflow = config_get( 'status_enum_workflow' . _ . category_get_name( bug_get_category_ID( $bug_id )) . _ . get_enum_element( 'access_levels', current_user_get_access_level() ), null, null, $p_project_id );
} elseif (config_get( 'status_enum_workflow' . _ . category_get_name( bug_get_category_ID( $bug_id )) , null, null, $p_project_id ) != null) {
$t_enum_workflow = config_get( 'status_enum_workflow'. _ . category_get_name( bug_get_category_ID( $bug_id )), null, null, $p_project_id );
} else {
$t_enum_workflow = config_get( 'status_enum_workflow_default', null, null, $p_project_id );
}
if( count( $t_enum_workflow ) < 1 ) {
Code: Select all
require_once( 'NEWFILE_api.php' );
Add the parameter to:
bug_update_advanced_page.php
bug_report_page.php (add to function print_status_option_list())
html_api.php
print_api.php
Now you have to disable the Exception Output for the workflow config. Usually you have one workflow defined in the config_inc.php file. If Mantis does not find it, it will display an error message "Application warning 100". Because of the new if statements, that loads different workflows, it could happen, that the error is displayed, despite the fact, that everything is alright. This happens because mantis now searches for different workflows till it finds the right one or jumps to the default one. To disable that error message you have to go to core/config_api.php and comment out the line "trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, WARNING );".
This is what I did. Like I said, I don't know if this is a good solution. I hope I could explain it good enough and I didn't forget anything.
Note, that you have to put all these changes in back in mantis, after you updated to a new version.
Best regards,
Mathias
Re: Change workflow based on selected category
Hey,
your changes work perfectly, but since the Mantis Update from Mantis 1.2.19 to Mantis 2.1.0 i have some problems with it.
I implemented all your changes in the new Version and now i have an Error when I'm clicking on a ticket.
APPLICATION ERROR #401
Datenbankabfrage fehlgeschlagen. Die Reportmeldung lautet #0: für die Abfrage: SELECT category_id
FROM mantis_bug_table
WHERE bug_text_id=495.
Do you have any ideas how to make Mantis work again with your workflow concept?
I'm happy for any answer.
Regards
your changes work perfectly, but since the Mantis Update from Mantis 1.2.19 to Mantis 2.1.0 i have some problems with it.
I implemented all your changes in the new Version and now i have an Error when I'm clicking on a ticket.
APPLICATION ERROR #401
Datenbankabfrage fehlgeschlagen. Die Reportmeldung lautet #0: für die Abfrage: SELECT category_id
FROM mantis_bug_table
WHERE bug_text_id=495.
Do you have any ideas how to make Mantis work again with your workflow concept?
I'm happy for any answer.
Regards
Re: Change workflow based on selected category
Hello all,
To anwser to the last question, with the new version of mantis (2.52.2), you need to change more things because some methods are now deprecated and some others must include the bug id.
I explain all here in my blog (sorry it's in french but the code is still in PHP ^^) : https://www.cidwe.com/2021/09/23/defini ... g-tracker/
To anwser to the last question, with the new version of mantis (2.52.2), you need to change more things because some methods are now deprecated and some others must include the bug id.
I explain all here in my blog (sorry it's in french but the code is still in PHP ^^) : https://www.cidwe.com/2021/09/23/defini ... g-tracker/
Re: Change workflow based on selected category
dead link..... 

Re: Change workflow based on selected category
Suggest you ccontact the woner of that site :
https://www.cidwe.com/contact/
https://www.cidwe.com/contact/