SugarCRM validate fields before_save in Logic Hook

219 Views Asked by At

SugarCRM Versión: 7.6

In modules Cases, I have two custom field Reason and Subreason.

I want when Reason = Returns, Subreason must be required.

In the Edit page in Javascript the validate works, but in the list cases, in edit row, doesn't work.

I'm trying with a Logic Hook but nothing works

With

echo "Hi";
die();

The console returns

SyntaxError: Unexpected token H in JSON at position 0

SugarApplication::appendErrorMessage, not returns anything and Save

SugarApplication::redirect, returns error

SyntaxError: Unexpected token < in JSON at position 0

Any solution?

Thanks

2

There are 2 best solutions below

1
Vikram On

You need to use list view logic hook.

0
Mohammed Jhosawa On

This can be achievable via before_save logic hook

<?php

class CaseBeforeSave {
  public function validateSubReasonField($bean, $event, $arguments)
  {
     if (!empty($bean->reason)
         && $bean->reason == "Returns"
         && empty($bean->subreason)
     ) {
        // This would throw error on UI
        throw SugarApiExceptionMissingParameter('Subreason is empty');
     }
   }
}

Hope this helps!