Costum filed suggest the next sequencial number.

Post about your customizations to share with others.

Moderators: Contributor, Developer

Costum filed suggest the next sequencial number.

Postby NandoNaldo » May 29, 2017 3:08 am

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 ?
NandoNaldo
 
Posts: 111
Joined: Mar 09, 2016 4:44 pm

Re: Costum filed suggest the next sequencial number.

Postby NandoNaldo » May 29, 2017 5:38 am

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 ?
Attachments
Autoincrement php.JPG
Autoincrement php.JPG (98.62 KiB) Viewed 1335 times
NandoNaldo
 
Posts: 111
Joined: Mar 09, 2016 4:44 pm

Re: Costum filed suggest the next sequencial number.

Postby atrol » May 31, 2017 12:45 am

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.
Please use Search before posting and read the Manual
Use Mantis2Go to try MantisBT on Windows or to reproduce issues
atrol
Site Admin
 
Posts: 6714
Joined: Mar 26, 2008 4:37 pm
Location: Germany

Re: Costum filed suggest the next sequencial number.

Postby 7h3ju57 » Jun 14, 2017 12:40 pm

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);
        }
}
7h3ju57
 
Posts: 6
Joined: May 05, 2017 3:36 pm


Return to Customizations

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests