custom field auto incrementing number [FIXED]

Post about your customizations to share with others.

Moderators: Contributor, Developer

custom field auto incrementing number [FIXED]

Postby 7h3ju57 » May 05, 2017 3:49 pm

hi all,

im trying to get an auto incrementing numerical field that would start with the year plus a number that increments with each new ticket opened. for example, user opens new issue, and field autoinc would have an auto generated number of 2017-1 (which ideally would be first ticket of the corresponding year). I've seen some examples for custom date and enumerating fields but nothing for string or numerical fields. any help would be greatly appreciated.
Last edited by 7h3ju57 on Jun 14, 2017 12:31 pm, edited 1 time in total.
7h3ju57
 
Posts: 6
Joined: May 05, 2017 3:36 pm

Re: custom field auto incrementing number

Postby 7h3ju57 » May 24, 2017 2:15 pm

someone must have some idea how to implement this?
7h3ju57
 
Posts: 6
Joined: May 05, 2017 3:36 pm

Re: custom field auto incrementing number

Postby NandoNaldo » May 26, 2017 7:51 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: custom field auto incrementing number

Postby 7h3ju57 » May 26, 2017 2:42 pm

only way i can think of is to have a file at the root of mantis with a variable. When you report a new issue it would pull that variables value and if you submit that issue then it overwrite the file with the new variable value. ie: var=2 + 1

not sure if this is the best way to implement though.
7h3ju57
 
Posts: 6
Joined: May 05, 2017 3:36 pm

Re: custom field auto incrementing number

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

Well i had some time to tinker around and was able to get my custom field number to increment using this.

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: No registered users and 11 guests