Page 1 of 1

Execute SQL command after create issue

Posted: 06 Jan 2022, 16:51
by mpa
Hi,

I need to update a custom_field (26) automatically after creating of an issue.
The data (name) is coming from a separate table 'DATA_table'.

I have created a new file 'custom_functions_inc.php' and located this file in the config folder.
Within the file i created an 'override' function, see below;

Code: Select all

function custom_function_override_issue_create_notify( $p_issue_id ) {
	$t_custom_field = 26;

	db_param_push();
	$t_query = 'SELECT `c`.`name`
				FROM {bug} AS b
				JOIN `DATA_table` AS c ON `b`.`category_id` = `c`.`category_id`
				WHERE `b`.`id` = ' . $p_issue_id . '';
	
	$t_result = db_query( $t_query );
	
	db_param_push();
	$t_query2 = 'INSERT INTO {custom_field_string} 
					(`field_id`,`bug_id`,`value`)
				VALUES
					( ' . $t_custom_field . ',' . $p_issue_id . ',' . $t_result .')';
					
	}
What im i doing wrong here? It doesn't seems to work at the moment. Or the function is not triggered?

Thanks for helping....

Re: Execute SQL command after create issue

Posted: 07 Jan 2022, 10:15
by cas
if you want to be sure the code is executed, simply add the following command ad the end of the function:
echo $t_query;
echo "<br>":
echt $t_query2;
echo "<br>":
die("execution");

If nothing happens, you know it is not executed, otherwise you also see the actual SQL statements that have been executed.
This way (assuming you do have a test environment) you will your problem soon enough :mrgreen:

Re: Execute SQL command after create issue

Posted: 09 Jan 2022, 01:46
by mpa
Thank you Cas,

It did help me find the problem.


I needed to add:
db_query( $t_query );

Thanks again!