CSV Export - custom fields
Moderators: Developer, Contributor
CSV Export - custom fields
Hi,
I have a custom field of type date called requested_finished_date. Now I want it to be shown in the CSV export, what do I need to do???
/A
I have a custom field of type date called requested_finished_date. Now I want it to be shown in the CSV export, what do I need to do???
/A
I used the custom_function_inc.php to override the standard function custom_function_default_get_columns_to_view that is defined in columns_api.php. In fact I copied the code of the original function and inserted output of custom fields.
Starting with V 1.0.0a3, Insert in custom_function_inc.php the following code:
# --------------------
# returns an array of the column names to be displayed.
# The column names to use are those of the field names in the bug table.
# In addition, you can use the following:
# - "selection" for selection checkboxes.
# - "edit" for icon to open the edit page.
# - "custom_xxxx" were xxxx is the name of the custom field that is valid for the
# current project. In case of "All Projects, the field will be empty where it is
# not applicable.
function custom_function_override_get_columns_to_view( $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
$t_columns = array();
if ( $p_columns_target == COLUMNS_TARGET_CSV_PAGE ) {
$t_columns[] = 'id'; // localized: 'id',
$t_columns[] = 'project_id'; // 'email_project'
$t_columns[] = 'reporter_id'; // 'reporter'
$t_columns[] = 'handler_id'; // 'assigned_to'
$t_columns[] = 'priority'; // 'priority'
$t_columns[] = 'severity'; // 'severity'
$t_columns[] = 'reproducibility'; // 'reproducibility'
$t_columns[] = 'version'; // 'version'
$t_columns[] = 'projection'; // 'projection'
$t_columns[] = 'category'; // 'category'
$t_columns[] = 'date_submitted'; // 'date_submitted'
$t_columns[] = 'eta'; // 'eta'
$t_columns[] = 'os'; // 'os'
$t_columns[] = 'os_build'; // 'os_version'
$t_columns[] = 'platform'; // 'platform'
$t_columns[] = 'view_state'; // 'view_status'
$t_columns[] = 'last_updated'; // 'last_update'
$t_columns[] = 'summary'; // 'summary'
$t_columns[] = 'status'; // 'status'
$t_columns[] = 'resolution'; // 'resolution'
$t_columns[] = 'fixed_in_version'; // 'fixed_in_version';
# if viewing only one Project, Add all custom fields linked to this project
if ( helper_get_current_project() != ALL_PROJECTS ) {
$t_custom_fields = custom_field_get_ids(helper_get_current_project());
foreach( $t_custom_fields as $t_field_id ) {
$t_desc = custom_field_get_definition( $t_field_id );
$t_columns[] = 'custom_' . $t_desc['name'];
}
}
if ( OFF == config_get( 'enable_relationship' ) ) {
$t_columns[] = 'duplicate_id'; // 'duplicate_id'
}
} else {
$t_columns[] = 'selection';
if ( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ) {
$t_columns[] = 'edit';
}
$t_columns[] = 'priority';
$t_columns[] = 'id';
$t_enable_sponsorship = config_get( 'enable_sponsorship' );
if ( ON == $t_enable_sponsorship ) {
$t_columns[] = 'sponsorship';
}
$t_columns[] = 'bugnotes_count';
$t_show_attachments = config_get( 'show_attachment_indicator' );
if ( ON == $t_show_attachments ) {
$t_columns[] = 'attachment';
}
$t_columns[] = 'reporter_id';
$t_columns[] = 'category';
$t_columns[] = 'severity';
$t_columns[] = 'status';
$t_columns[] = 'last_updated';
$t_columns[] = 'summary';
}
return $t_columns;
}
Starting with V 1.0.0a3, Insert in custom_function_inc.php the following code:
# --------------------
# returns an array of the column names to be displayed.
# The column names to use are those of the field names in the bug table.
# In addition, you can use the following:
# - "selection" for selection checkboxes.
# - "edit" for icon to open the edit page.
# - "custom_xxxx" were xxxx is the name of the custom field that is valid for the
# current project. In case of "All Projects, the field will be empty where it is
# not applicable.
function custom_function_override_get_columns_to_view( $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
$t_columns = array();
if ( $p_columns_target == COLUMNS_TARGET_CSV_PAGE ) {
$t_columns[] = 'id'; // localized: 'id',
$t_columns[] = 'project_id'; // 'email_project'
$t_columns[] = 'reporter_id'; // 'reporter'
$t_columns[] = 'handler_id'; // 'assigned_to'
$t_columns[] = 'priority'; // 'priority'
$t_columns[] = 'severity'; // 'severity'
$t_columns[] = 'reproducibility'; // 'reproducibility'
$t_columns[] = 'version'; // 'version'
$t_columns[] = 'projection'; // 'projection'
$t_columns[] = 'category'; // 'category'
$t_columns[] = 'date_submitted'; // 'date_submitted'
$t_columns[] = 'eta'; // 'eta'
$t_columns[] = 'os'; // 'os'
$t_columns[] = 'os_build'; // 'os_version'
$t_columns[] = 'platform'; // 'platform'
$t_columns[] = 'view_state'; // 'view_status'
$t_columns[] = 'last_updated'; // 'last_update'
$t_columns[] = 'summary'; // 'summary'
$t_columns[] = 'status'; // 'status'
$t_columns[] = 'resolution'; // 'resolution'
$t_columns[] = 'fixed_in_version'; // 'fixed_in_version';
# if viewing only one Project, Add all custom fields linked to this project
if ( helper_get_current_project() != ALL_PROJECTS ) {
$t_custom_fields = custom_field_get_ids(helper_get_current_project());
foreach( $t_custom_fields as $t_field_id ) {
$t_desc = custom_field_get_definition( $t_field_id );
$t_columns[] = 'custom_' . $t_desc['name'];
}
}
if ( OFF == config_get( 'enable_relationship' ) ) {
$t_columns[] = 'duplicate_id'; // 'duplicate_id'
}
} else {
$t_columns[] = 'selection';
if ( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ) {
$t_columns[] = 'edit';
}
$t_columns[] = 'priority';
$t_columns[] = 'id';
$t_enable_sponsorship = config_get( 'enable_sponsorship' );
if ( ON == $t_enable_sponsorship ) {
$t_columns[] = 'sponsorship';
}
$t_columns[] = 'bugnotes_count';
$t_show_attachments = config_get( 'show_attachment_indicator' );
if ( ON == $t_show_attachments ) {
$t_columns[] = 'attachment';
}
$t_columns[] = 'reporter_id';
$t_columns[] = 'category';
$t_columns[] = 'severity';
$t_columns[] = 'status';
$t_columns[] = 'last_updated';
$t_columns[] = 'summary';
}
return $t_columns;
}
bug with relationships off?
First off, thanks for that code chunk, it was a HUGE help! I have v1.0.3 and wasnt able to export the custom fields. After disabling relationships (didnt need them) I started getting an error in the export too.
I noticed if I comment out this line in your post...
...then it was working just fine.
I also found other posts (in my research for a solution) that claimed duplicate_id was no longer needed as it was an artifact from earlier development.
Just thought I would share in case someone else has the same difficulties
I noticed if I comment out this line in your post...
Code: Select all
$t_columns[] = 'duplicate_id'; // 'duplicate_id'
I also found other posts (in my research for a solution) that claimed duplicate_id was no longer needed as it was an artifact from earlier development.
Just thought I would share in case someone else has the same difficulties
duplicate_id is only used if relationships are disabled. It is your only way to store the fact that one issue is a duplicate of another.
The way to do this customisation has changed in v1.1, and even if you use custom functions, duplicate_id will not cause an error (I think I fixed that!).
Regards,
Victor
MantisConnect
http://www.futureware.biz/mantisconnect/
The way to do this customisation has changed in v1.1, and even if you use custom functions, duplicate_id will not cause an error (I think I fixed that!).
Regards,
Victor
MantisConnect
http://www.futureware.biz/mantisconnect/
First, this thread was very helpful.
I used this code and found that it gets ALL of the custom fields that you have in Mantis. To only get the fields assocaited with THIS project, replace:
with
I used this code and found that it gets ALL of the custom fields that you have in Mantis. To only get the fields assocaited with THIS project, replace:
Code: Select all
$t_custom_fields = custom_field_get_ids(helper_get_current_project());
Code: Select all
$t_custom_fields = custom_field_get_linked_ids(helper_get_current_project());
In Mantis 1.0.3 I had to name the file custom_functions_inc.phphgaland wrote:I used the custom_function_inc.php to override the standard function custom_function_default_get_columns_to_view that is defined in columns_api.php.
In Mantis 1.0.3 you must use:hgaland wrote: # if viewing only one Project, Add all custom fields linked to this project
if ( helper_get_current_project() != ALL_PROJECTS ) {
$t_custom_fields = custom_field_get_ids(helper_get_current_project());
foreach( $t_custom_fields as $t_field_id ) {
$t_desc = custom_field_get_definition( $t_field_id );
$t_columns[] = 'custom_' . $t_desc['name'];
}
}
$t_custom_fields = custom_field_get_linked_ids(helper_get_current_project());
For the rest: good job.
@developers: please consider this change for the next release
greetz
Alexander
remove some column in csv export
I have to remove following fields from csv export.
1) Reporter
2) Assigned_to
3) priority
4) Severity
5) Reporoducibility
6) product version
7) projection
8) ETA
9) os
10) osserver
11) plate form
12) view status
13) Resolution
14) fixed in version.
As per this thread, i have create custom_function_inc.php in /matis folder & public_html folder.
Commented all above fields but still in csv export all above fileds is coming.
I don't know php. Can some body will help me.
thanks in advanced.
1) Reporter
2) Assigned_to
3) priority
4) Severity
5) Reporoducibility
6) product version
7) projection
8) ETA
9) os
10) osserver
11) plate form
12) view status
13) Resolution
14) fixed in version.
As per this thread, i have create custom_function_inc.php in /matis folder & public_html folder.
Commented all above fields but still in csv export all above fileds is coming.
I don't know php. Can some body will help me.
thanks in advanced.
I have probed this modification but I have a problem. When I want to export a lot of events, I have a timeot error like this.
Tipo de suceso: Error
Origen del suceso: W3SVC
Categoría del suceso: Ninguno
Id. suceso: 16
Fecha: 11/07/2007
Hora: 11:20:21
Usuario: No disponible
Equipo: xxxxx
Descripción:
La secuencia de comandos iniciada desde la dirección URL "/xxxx/csv_export.php" con los parámetros "" no ha respondido dentro del tiempo de espera configurado. El servidor HTTP va a abandonar la secuencia de comandos.
Para recibir información adicional referente a este mensaje, visite el sitio Web de soporte técnico de Microsoft que se encuentra en: http://www.microsoft.com/contentredirect.asp.
I'm changing some server parameters like IIS, PHP, MySQL but it doesn't work. Any idea?
Thank you.
Tipo de suceso: Error
Origen del suceso: W3SVC
Categoría del suceso: Ninguno
Id. suceso: 16
Fecha: 11/07/2007
Hora: 11:20:21
Usuario: No disponible
Equipo: xxxxx
Descripción:
La secuencia de comandos iniciada desde la dirección URL "/xxxx/csv_export.php" con los parámetros "" no ha respondido dentro del tiempo de espera configurado. El servidor HTTP va a abandonar la secuencia de comandos.
Para recibir información adicional referente a este mensaje, visite el sitio Web de soporte técnico de Microsoft que se encuentra en: http://www.microsoft.com/contentredirect.asp.
I'm changing some server parameters like IIS, PHP, MySQL but it doesn't work. Any idea?
Thank you.
I can't understand your post. But I had a look at the latest code and found that it calls helper_begin_long_process() which shouldn't make the script time out.
If in your version it is not called, then call it after auth_ensure_user_authenticated().
If in your version it is not called, then call it after auth_ensure_user_authenticated().
Migrate your MantisBT to the MantisHub Cloud
Re: CSV Export - custom fields
Great work! Thank you for the help and code!
Just a note...perhaps a silly one, but it took me a few minutes to figure it out. If you have custom fields, that apply to all projects, you can remove the 'if' statement that restricts it to just the specific projects.
I only export for all projects that are open, so, with the if statement, it's not helpful in my situation.
Hope that is helpful to someone
Just a note...perhaps a silly one, but it took me a few minutes to figure it out. If you have custom fields, that apply to all projects, you can remove the 'if' statement that restricts it to just the specific projects.
I only export for all projects that are open, so, with the if statement, it's not helpful in my situation.
Hope that is helpful to someone
-
- Posts: 1
- Joined: 08 Jan 2013, 13:36
Re: CSV Export - custom fields
Hello !
Below is a custom code that exports all current project's custom fields, and interprets field named like "*charge*" (ie. workload in french) values in hours into days.
This way you can get CSV exports of your project's tickets and sum up the "*charge*" columns with a spreadsheet/Excel-like application.
This worked well for Mantis v1.0.0 rc1.
Below is a custom code that exports all current project's custom fields, and interprets field named like "*charge*" (ie. workload in french) values in hours into days.
This way you can get CSV exports of your project's tickets and sum up the "*charge*" columns with a spreadsheet/Excel-like application.
This worked well for Mantis v1.0.0 rc1.
Code: Select all
<?php
# --------------------
# returns an array of the column names to be displayed.
# The column names to use are those of the field names in the bug table.
# In addition, you can use the following:
# - "selection" for selection checkboxes.
# - "edit" for icon to open the edit page.
# - "custom_xxxx" were xxxx is the name of the custom field that is valid for the
# current project. In case of "All Projects, the field will be empty where it is
# not applicable.
// @see http://www.mantisbt.org/forums/viewtopic.php?t=400
function custom_function_override_get_columns_to_view($p_columns_target = COLUMNS_TARGET_VIEW_PAGE)
{
$t_columns = array();
if ($p_columns_target == COLUMNS_TARGET_CSV_PAGE) {
$t_columns[] = 'id'; // localized: 'id',
$t_columns[] = 'project_id'; // 'email_project'
$t_columns[] = 'reporter_id'; // 'reporter'
$t_columns[] = 'handler_id'; // 'assigned_to'
$t_columns[] = 'priority'; // 'priority'
$t_columns[] = 'severity'; // 'severity'
$t_columns[] = 'reproducibility'; // 'reproducibility'
$t_columns[] = 'version'; // 'version'
$t_columns[] = 'projection'; // 'projection'
$t_columns[] = 'category'; // 'category'
$t_columns[] = 'date_submitted'; // 'date_submitted'
$t_columns[] = 'eta'; // 'eta'
$t_columns[] = 'os'; // 'os'
$t_columns[] = 'os_build'; // 'os_version'
$t_columns[] = 'platform'; // 'platform'
$t_columns[] = 'view_state'; // 'view_status'
$t_columns[] = 'last_updated'; // 'last_update'
$t_columns[] = 'summary'; // 'summary'
$t_columns[] = 'status'; // 'status'
$t_columns[] = 'resolution'; // 'resolution'
$t_columns[] = 'fixed_in_version'; // 'fixed_in_version';
# if viewing only one Project, Add all custom fields linked to this project
if (helper_get_current_project() != ALL_PROJECTS) {
$t_custom_fields = custom_field_get_linked_ids(helper_get_current_project());
foreach ($t_custom_fields as $t_field_id) {
$t_desc = custom_field_get_definition($t_field_id);
$t_columns[] = 'custom_' . $t_desc['name'];
}
}
if (OFF == config_get('enable_relationship')) {
$t_columns[] = 'duplicate_id'; // 'duplicate_id'
}
} else {
$t_columns[] = 'selection';
if ($p_columns_target == COLUMNS_TARGET_VIEW_PAGE) {
$t_columns[] = 'edit';
}
$t_columns[] = 'priority';
$t_columns[] = 'id';
$t_enable_sponsorship = config_get('enable_sponsorship');
if (ON == $t_enable_sponsorship) {
$t_columns[] = 'sponsorship';
}
$t_columns[] = 'bugnotes_count';
$t_show_attachments = config_get('show_attachment_indicator');
if (ON == $t_show_attachments) {
$t_columns[] = 'attachment';
}
$t_columns[] = 'reporter_id';
$t_columns[] = 'category';
$t_columns[] = 'severity';
$t_columns[] = 'status';
$t_columns[] = 'last_updated';
$t_columns[] = 'summary';
}
return $t_columns;
}
# --------------------
# Print the value of the custom field (if the field is applicable to the project of
# the specified issue and the current user has read access to it.
# see custom_function_default_print_column_title() for rules about column names.
# $p_column: name of field to show in the column.
# $p_row: the row from the bug table that belongs to the issue that we should print the values for.
# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
// @see "NOTE ..." comment within this function for actual overriding code
function custom_function_override_print_column_value( $p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
if ( COLUMNS_TARGET_CSV_PAGE == $p_columns_target ) {
$t_column_start = '';
$t_column_end = '';
$t_column_empty = '';
} else {
$t_column_start = '<td>';
$t_column_end = '</td>';
$t_column_empty = ' ';
}
if ( strpos( $p_column, 'custom_' ) === 0 ) {
echo $t_column_start;
$t_custom_field = substr( $p_column, 7 );
$t_field_id = custom_field_get_id_from_name( $t_custom_field );
if ( $t_field_id === false ) {
echo '@', $t_custom_field, '@';
if(stristr($p_column,'charge') !== FALSE) echo 'THERE3'; //TODO
} else {
$t_issue_id = $p_issue_row['id'];
$t_project_id = $p_issue_row['project_id'];
if ( custom_field_is_linked( $t_field_id, $t_project_id ) ) {
$t_def = custom_field_get_definition( $t_field_id );
// NOTE: FIELD REWRITING HACK IS HERE
//print_custom_field_value( $t_def, $t_field_id, $t_issue_id );
$_val = string_custom_field_value( $t_def, $t_field_id, $t_issue_id );
$_val_rewritten = rewrite_custom_field_value($p_column, $_val);
echo empty($_val) ? $t_column_empty : $_val_rewritten;
} else {
// field is not linked to project
echo $t_column_empty;
}
}
echo $t_column_end;
} else {
if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
$t_function = 'print_column_' . $p_column;
} else {
$t_function = 'csv_format_' . $p_column;
}
if ( function_exists( $t_function ) ) {
if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
$t_function( $p_issue_row, $p_columns_target );
} else {
$t_function( $p_issue_row[$p_column] );
}
} else {
if ( isset( $p_issue_row[$p_column] ) ) {
echo $t_column_start . $p_issue_row[$p_column] . $t_column_end;
} else {
echo $t_column_start . '@' . $p_column . '@' . $t_column_end;
}
}
}
}
// Rewrite 'Charge' and 'Charge reelle' custom fields before CSV export.
function rewrite_custom_field_value($p_column,$value) {
// Rewrite work load duration values into days without suffix.
if(stristr($p_column,'charge') !== FALSE) {
$original_value = $value;
// Convert decimals separator to . before number conversion
$value = str_replace(',','.',$value);
// Try to convert days or hours to days.
$value = duration_string_days_float($value);
if(!is_numeric($value)) {
$value = $original_value;
}
// Replace number . by \, for MS Excel badly reading CSV.
$value = str_replace('.',',',$value);
}
return $value;
}
//Parse string in 'N hours' or 'N days' into a 0.01-precision number of 8-hours-work days
function duration_string_days_float($value) {
// If is hours, convert to days.
$value_hours = preg_replace('/(hours|hour|heures|heure|h)/i','', $value);
if($value_hours != $value) {
$value_days = floatval($value_hours) / 8.0;
// If is days, keep days as is.
} else {
$value_days = preg_replace('/(days|day|jours|jour|j|d)/i','', $value);
}
// Round at 0.01 precision.
$value = round(floatval($value_days), 2);
return $value;
}
Re: CSV Export - custom fields
Where is this code tell me in mantis folder or if it's ur own code where it should be added i have to add additional field which should be displayed CSV excel file
in one fourm it was said add this below coding from config_default_inc.php to config_inc.php but it doesn't worked same error came
$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count',
'attachment', 'category','severity', 'status', 'last_updated', 'summary' );
$g_print_issues_page_columns = array ( 'selection', 'priority', 'id', 'sponsorship_total', 'bugnotes_count',
'attachment', 'category', 'severity', 'status', 'last_updated', 'summary');
$g_csv_columns = array ( 'id', 'project_id', 'reporter_id', 'handler_id', 'priority', 'reproducibility', 'category',
'date_submitted','view_state', 'last_updated', 'summary', 'status', 'resolution','cspl columns');
this is the Error i am getting in Excel file
<p style="color:red">APPLICATION WARNING #300: String "CSPLcolumns" not found.</p>
NOTE : i dont have this file custom_functions_inc.php
can any one help me
in one fourm it was said add this below coding from config_default_inc.php to config_inc.php but it doesn't worked same error came
$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count',
'attachment', 'category','severity', 'status', 'last_updated', 'summary' );
$g_print_issues_page_columns = array ( 'selection', 'priority', 'id', 'sponsorship_total', 'bugnotes_count',
'attachment', 'category', 'severity', 'status', 'last_updated', 'summary');
$g_csv_columns = array ( 'id', 'project_id', 'reporter_id', 'handler_id', 'priority', 'reproducibility', 'category',
'date_submitted','view_state', 'last_updated', 'summary', 'status', 'resolution','cspl columns');
this is the Error i am getting in Excel file
<p style="color:red">APPLICATION WARNING #300: String "CSPLcolumns" not found.</p>
NOTE : i dont have this file custom_functions_inc.php
can any one help me