Hello,
I'am trying to find the same thing. I want to add a costum field, where i can put the id of my clients and everytime i have a new client, this filed could suggest the next sequencial number. Is this possible ?
Costum filed suggest the next sequencial number.
Moderators: Developer, Contributor
-
- Posts: 122
- Joined: 09 Mar 2016, 21:44
-
- Posts: 122
- Joined: 09 Mar 2016, 21:44
Re: Costum filed suggest the next sequencial number.
I noticed in the phpmyadmin that the id has an extra comment: AUTO_INCREMENT
I was thinking: if i add a new filed with this extra comment, am i able to have a field that increments by it self ?
I was thinking: if i add a new filed with this extra comment, am i able to have a field that increments by it self ?
- Attachments
-
- Autoincrement php.JPG (98.62 KiB) Viewed 6500 times
Re: Costum filed suggest the next sequencial number.
Using AUTO_INCREMENT is the right way in MySQL for sequences (does not work with other databases).
But you can't use this for standard MantisBT custom fields. You can use it just for columns of tables that you created by your own.
But you can't use this for standard MantisBT custom fields. You can use it just for columns of tables that you created by your own.
Re: Costum filed suggest the next sequencial number.
Well i had some time to tinker around and was able to get my custom field number to increment using this.
Hope this helps
Hope this helps
Code: Select all
function custom_function_override_issue_create_notify( $p_issue_id ) {
#Get custom field id by field name
$t_id = custom_field_get_id_from_name( 'fieldname' );
#Get the current yeat
$c_year = date("Y");
#Get the last created tickets field value
$latest_x = custom_field_get_value($t_id ,($p_issue_id - 1));
#Substring manipulation (extracting the year from the custom field)
$x_year = substr($latest_x, 0, 4);
#Substring manipulation (extract incrmental number)
$x_num = substr($latest_x, 5);
#Increment the number by 1
$new_x = ($x_num + 1);
#Verify that we are in the same year.
if($x_year == $c_year){
#If we are, increment the number
custom_field_set_value( $t_id, $p_issue_id, $c_year . '-' . $new_x, $p_log_insert = false);
} else {
#If not set number to 1
custom_field_set_value( $t_id, $p_issue_id, $c_year . '-' . '1', $p_log_insert = false);
}
}