Adding user input into Edited field

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'])){

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

                //if ticket status is closed then it displays an error message
                $module = BeanFactory::getBean("CUSTOM MODULE", $bean->field_name);
                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();
                }
            }
         //edit function
        } elseif ($_REQUEST['action'] == 'EditView') {
          //code here

        //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));
        }

    }
}
Parents Reply Children
  • Hi karl el escobar,

    You can do it through logic hook using sugar exception class to block the save if condition fails and keep the current record in edit mode so that user can fill in proper value.

    if(condtion fail) {
        throw new SugarApiExceptionInvalidParameter("Cannot save record, condition doesn't meet.");
    }

    You can check out the list of available exceptions here - <sugar_dir>/include/api/SugarApiException.php

    Please note, with above customization in place, you cannot highlight the field where the error has occurred (you can just show an exception with a message) and this logic will get triggered from all the platforms (web, mobile etc.) meaning if your user is coming from mobile app or through import wizard, this logic will be executed and block the record save if condition doesn't meet.

    Regards.