after save logic hook breaks audit

I created an after_save logic hook in the Cases module that checks if the status == Resolved then it redirects back to the view cases screen. That works just fine but the problem is it no longer shows in the change log that the user changed the status to Resolved. If I remove the logic hook, then it shows up in the change log again. Does anyone know of a way to fix this?

Can you post the function call of your logic hook? The audit bean happens after the after_save logic hooks are called so there is likely something in there preventing the audit from being processed.

Sure. Here is my logic hook. Maybe there is a way to make the audit happen before the redirect?

class back_to_cases_class
    {
        function back_to_cases_method($bean, $event, $arguments)
        {
		if ($bean->state == "Closed") {
		
			SugarApplication::redirect('/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCases%26action%3Dindex' . http_build_query($queryParams));
	}
   }
    }

I haven’t had a chance to test yet but I was thinking of instead of doing an explicit redirect you may try setting the return_module and return_action parameters.

Thanks for your suggestion Shad, I tried doing it with the code below but it still seems to happen before the audit bean.

function back_to_cases_method($bean, $event, $arguments)
        {
		if ($bean->state == "Closed") {
		$queryParams = array(
			'module' => 'Cases',
			'return_action' => 'Cases'
		);
		SugarApplication::redirect('index.php?' . http_build_query($queryParams));

I was thinking of something like $_GET[‘return_action’] = ‘ListView’; $_GET[‘return_module’] = ‘Cases’;

This way you can use the system to take you back where you want after the save function. Again I haven’t had a chance to try. LMK if you are still having trouble and I should have some time tomorrow to try this out.

Take care

Hi,
I Try too :wink:

logic_hook have “sort” value : 1, 10, 100, … so one is fire before 10. Maybe try to put this on a bigger valuer !?

Other solution maybe :
create un new views/view.edit.php

And on function display… make if … en then redirect to DetailView ?

Maybe…
Regards

I wasn’t able to get it to work. If you get some free time to test it out tomorrow, I would be greatful.

Thanks for the help item. I currently have it set to 180 and it still is occurring before the audit bean.

I tried doing this but it doesn’t seem to be redirecting, would you be able to show the correct code I need to use?

I have just do for ours instance … but you must adapt for Cases and edit view
I don’t know if redirect work

file is in custom/modules/Accounts/views/view.edit.php



<?php
require_once('modules/Accounts/views/view.edit.php');


class CustomAccountsViewEdit extends AccountsViewEdit
{

    public function __construct()
    {
    	parent::AccountsViewEdit();
    }

	public function display()
	{
		global $current_user, $db;
		
		$action = $_REQUEST['action'];
		$module = $_REQUEST['module']; 
		$record = $_REQUEST['record'];
		
		// DO REDIRECT IF THEN REDIRECT VIEW.DETAIL,PHP
                // IF STATUS == THEN..
		
		parent::display();
		
	}

}



Yes it’s works…it redirect :wink:

1 Like

This should work.

if ($bean->state == “Closed”) {
$bean->auditBean (true);
SugarApplication::redirect(‘index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCases%26action%3Dindex’);
}

2 Likes

That’s exactly what I needed! Thanks so much for you help shad.