Page 1 of 1

Showing specified custom fields on email report

Posted: 31 Aug 2007, 13:58
by danich
Let's say that you have lots of custom fields in your report and when a new issue is submited you are interested in showing only certain custom fields.
Open 'core/email_api.php'
Find the code: (about line 973)

Code: Select all

# custom fields formatting
foreach( $p_visible_bug_data['custom_fields'] as $t_custom_field_name => $t_custom_field_data ) {
       $t_message .= str_pad( lang_get_defaulted( $t_custom_field_name, null ) . ': ', $t_email_padding_length, ' ', STR_PAD_RIGHT );
       $t_message .= string_custom_field_value_for_email ( $t_custom_field_data['value'], $t_custom_field_data['type'] );
       $t_message .= " \n";
} # end foreach custom field
Replace it with:

Code: Select all

# custom fields formatting
foreach( $p_visible_bug_data['custom_fields'] as $t_custom_field_name => $t_custom_field_data ) 
{
		if( $t_custom_field_name == 'Custom field name' ){# Mostrar solo x custom field en el envĂ­o de mails
			$t_message .= str_pad( lang_get_defaulted( $t_custom_field_name, null ) . ': ', $t_email_padding_length, ' ', STR_PAD_RIGHT );
			$t_message .= string_custom_field_value_for_email ( $t_custom_field_data['value'], $t_custom_field_data['type'] );
			$t_message .= " \n";}
		} # end foreach custom field
If you want to show more than one specific custom field, use the case sentence as follows:

Code: Select all

		# custom fields formatting
		foreach( $p_visible_bug_data['custom_fields'] as $t_custom_field_name => $t_custom_field_data ) 
		{
		 switch ($t_custom_field_name) {
			case 'Custom field 1':
			$t_message .= str_pad( lang_get_defaulted( $t_custom_field_name, null ) . ': ', $t_email_padding_length, ' ', STR_PAD_RIGHT );
			$t_message .= string_custom_field_value_for_email ( $t_custom_field_data['value'], $t_custom_field_data['type'] );
			$t_message .= " \n";
			break;
			case 'Custom field 2':
			$t_message .= str_pad( lang_get_defaulted( $t_custom_field_name, null ) . ': ', $t_email_padding_length, ' ', STR_PAD_RIGHT );
			$t_message .= string_custom_field_value_for_email ( $t_custom_field_data['value'], $t_custom_field_data['type'] );
			$t_message .= " \n";
			break;
Just replace the "'Custom field name'" with the custom field you'd like to appear in the email.



Tested in Mantis 1.1.0a3, works fine.
Cheers !