Menu
Welcome, Guest
Username: Password: Remember me

TOPIC: Redirect to calendar after save

Redirect to calendar after save 1 week 3 days ago #91518

  • jalamani
  • jalamani's Avatar
  • Offline
  • Junior Member
  • Posts: 29
  • Karma: 0
I am following the Logic Hook documentation but got tripped up along the way since it is not working.

This logic hook is intended to redirect to the Calendar module instead of the default Detailview after save of a custom module.

\custom\modules\time_MonthlyTimesheet\Logic_Hooks.php
<?php
// Do not store anything in this file that is not part of the array or the hook version.  This file will	
// be automatically rebuilt in the future. 
 $hook_version = 1; 
$hook_array = Array(); 
// position, file, function 
$hook_array['after_save'] = Array(); 
$hook_array['after_save'][] = Array(1, 'Post save redirect', 'custom/modules/time_MonthlyTimesheet/postsaveRedirect.php','postsaveRedirect', 'redirect'); 


?>

\custom\modules\time_MonthlyTimesheet\postsaveRedirect.php
<?php
 
class postsaveRedirect
{
    public function redirect(SugarBean $bean, $event, $arguments)
    {
        if ($bean->module_name == 'time_MonthlyTimesheet') {
            return;
        }
        if (defined('sugarEntry') && defined('SUGARCRM_IS_INSTALLING')) {
            return;
        }
        try {
            $params = array(
            'module'=> 'Calendar',
            'action'=>'index', 
            'parentTab' => 'all'
        );
        SugarApplication::redirect('index.php?' . http_build_query($params));
            // header('Location: http://127.0.0.1/SuiteCRM/index.php?module=Calendar&action=index&parentTab=All');
            // exit;
        } catch (Exception $ex) {
            $GLOBALS['log']->error($ex->getMessage());
        }
    }

}

If anyone could correct my code or the placement of these files in the directory, it would be greatly appreciated.
Last Edit: 1 week 3 days ago by jalamani.
The administrator has disabled public write access.

Redirect to calendar after save 1 week 3 days ago #91527

  • suitecrm_developer
  • suitecrm_developer's Avatar
  • Offline
  • SuiteCRM Is My Life
  • 7 year experienced Freelancer PHP Developer
  • Posts: 391
  • Thank you received: 49
  • Karma: 7
Hi,
One Error is in FUNCTION defination

You should not define the param "$bean" like this
public function redirect(SugarBean $bean, $event, $arguments)

It should be like this
public function redirect(&$bean, $event, $arguments)

And

Also remove these
if ($bean->module_name == 'time_MonthlyTimesheet') {
            return;
        }
        if (defined('sugarEntry') && defined('SUGARCRM_IS_INSTALLING')) {
            return;
        }

Because there is no purpose to write them here. The Code is OK. I have also tested it for redirection.

Thanks a lot
********* For any instant help and discussion skype me. **********
Skype ==>> sohaib.majeed44
********* I am also available for SuiteCRM development tasks. **********
::MY PROFESSIONAL PROFILE::
Upwork ==>> www.upwork.com/fl/sohaibmajeed?viewMode=1
The administrator has disabled public write access.
The following user(s) said Thank You: jalamani

Redirect to calendar after save 6 days 16 hours ago #91680

  • jalamani
  • jalamani's Avatar
  • Offline
  • Junior Member
  • Posts: 29
  • Karma: 0
ty those if statements were breaking it
The administrator has disabled public write access.
Time to create page: 0.071 seconds
Powered by Kunena Forum