Page 1 of 1

Costum filed suggest the next sequencial number.

Posted: 29 May 2017, 08:08
by NandoNaldo
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 ?

Re: Costum filed suggest the next sequencial number.

Posted: 29 May 2017, 10:38
by NandoNaldo
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 ?

Re: Costum filed suggest the next sequencial number.

Posted: 31 May 2017, 05:45
by atrol
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.

Re: Costum filed suggest the next sequencial number.

Posted: 14 Jun 2017, 17:40
by 7h3ju57
Well i had some time to tinker around and was able to get my custom field number to increment using this.
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);
        }
}