0

I want to add an edit function if user decides to change the field value but i cant seem to find the right way to do this. Ive tried searching through google but it doesn't give any answer related for this problem.

code here:

<?php

class CloseTicket
{
    public function do_CloseTicket($bean, $events, $args)
    {
        //checks if the ticket is already in use
        if(!isset($bean->fetched_row['field_name_id'])){

            if (!empty($bean->field_name)) {

                //if ticket status is closed then it displays an error message
                $module = BeanFactory::getBean("CUSTOM MODULE", $bean->field_name_id);
                if ($module->status == 'Closed') {

                    SugarApplication::appendErrorMessage("Ticket is already used. Please use another Ticket.");
                    $params = array(
                        'module' => 'Module',
                        'action' => 'ListView',
                        'record' => $bean->id,
                    );
                    SugarApplication::redirect('index.php?' . http_build_query($params));

                //else adds the ticket then closed it    
                } else {
                    $module->status = "Closed";
                    $module->save();
                }
            }
        //if ticket is already taken then it display an error message    
        } else {
            SugarApplication::appendErrorMessage("Ticket is already attached.");
            $params = array(
                'module' => 'module',
                'action' => 'ListView',
                'record' => $bean->id,
            );
            SugarApplication::redirect('index.php?' . http_build_query($params));
        }

    }
}
s0m3d3v
  • 177
  • 1
  • 13

1 Answers1

0

I can't fully understand your issue.

But if you are trying to edit the duplicated related bean the params should be EditView instead of ListView like this:

$params = array(
                    'module' => 'Module',
                    'action' => 'EditView',
                    'record' => $bean->id,
                );
                SugarApplication::redirect('index.php?' . http_build_query($params));
mrbarletta
  • 902
  • 11
  • 17
  • my problem is i want the user to edit field even if it already has value but the ErrorMessage "Ticket is already attached." always pops up when i try to edit the value and put a different value. – s0m3d3v Apr 21 '19 at 13:52
  • sorry @allenconbulan I can't fully understand what your are trying to accomplish :( – mrbarletta Apr 23 '19 at 04:18