Debugging of custom functions

General discussion of Mantis.

Moderators: Developer, Contributor

Post Reply
lskearney
Posts: 2
Joined: 10 Jan 2018, 16:25

Debugging of custom functions

Post by lskearney »

I'm a newbie with mantis coding and am trying to write a custom function to validate an update according to a set of rules. After much trial and error, I have the function being invoked when I click the update issue button but am struggling in figuring out how to access the values of several custom fields so that I can check to see if at least one of them contains a non-zero value, throwing an exception if not. Here is what I have

Code: Select all

function custom_function_override_issue_update_validate( $p_issue_id, BugData $p_new_issue_data, $p_bugnote_text ) {
    $t_issue = bug_get( $p_issue_id );

    if ($t_issue->status == INVESTIGATE && $p_new_issue_data->status == Proposal) {
        // Get the values for the fields
        $annual_costs = custom_field_get_value('Estimated Annual Costs', $p_issue_id);
        $est_hours = custom_field_get_value('Estimated Hours', $p_issue_id);
        $est_costs = custom_field_get_value('Estimated Initial Costs', $p_issue_id);

        // At least one of these fields must have a non-zero value, otherwise, throw
        // an exception
        if ($annual_costs == 0.0 && $est_hours == 0.0 && $est_costs == 0.0) {
            error_parameters('this is testing to verify override function is activated');
            trigger_error(ERROR_VALIDATE_FAILURE, ERROR);
        }
    }
}
I know that I'm comparing the before and after status values but I can't tell what the retrieved custom field values are. In fact, the code shown is throwing a #1300 exception stating that the custom field name wasn't found. I've double checked the spelling both in my code and in the database table and they match exactly so I am speculating that I'm not using the function correctly or that I should be using another way to retrieve these values. Help would be appreciated here.

Basically, I need to know if there is some technique I can use to debug. I tried using printf statements but I don't know where the results are displayed and, AFAIK, there is no debugger (like GDB) which I can use to set breakpoints and examine variables.
atrol
Site Admin
Posts: 8366
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Debugging of custom functions

Post by atrol »

The first parameter of function custom_field_get_value is the custom field ID, it's not the name.
Please use Search before posting and read the Manual
lskearney
Posts: 2
Joined: 10 Jan 2018, 16:25

Re: Debugging of custom functions

Post by lskearney »

Yeah, I figured that out and made the necessary changes. I now seem to be successfully retrieving the values of the custom fields (based on the fact that no error is being thrown) but I still don't know what is actually being retrieved. I've set the values of the custom fields to be non-zero and then transitioned the status from 'investigate' to 'proposal' but the ERROR_VALIDATE_FAILURE is still being thrown which tells me that I'm not retrieving the values I expect.

Is there some way to print out the values after they've been fetched with the get_value function but before the if statement checking to see if all three values are 0?
Post Reply