How stop saving in before_save logichook?

Hi,

In my case in before_save I create jobQueue record and don’t want to do saving, how can I stop saving from before_save logichook?

That’s a nice question and I would love to know the answer…

This guy here does it by throwing an exception:
https://community.sugarcrm.com/thread/21640

but I don’t know if that applies to SuiteCRM as well. Can you try it and let us know if it worked? Thanks!

1 Like

Thanks, for help!

code from example:


require_once 'include/api/SugarApiException.php';

throw new SugarApiExceptionInvalidParameter("{$email} is already exist");

I try to search class SugarApiException, but there is no folder api in include folder of suite crm, and no sugarApiException.php :frowning:

How about using just this:

throw new Exception

That’s just an idea for something to try, I don’t really know much about this issue…

I did check the SuiteCRM code and there is no return value from before_save hooks. Typically you would just return false to keep the hook from saving, but that does not apply here…

Yes, I tryed a simple Exeption, it is stop the script and I have white page without any data.

Any ideas?

If you are using this logic hook to add to a job queue have you considered using an after save logic hook? Or as an alternative have a job search for saved records and add to the queue.

The Mass Update of many records take many time and I want create job queue to do this, so i don’t need been saving in real time and I want stop save in before save hook, only create queue record.

  1. I need form like mass update form to take values
  2. I need create job queue to do some update logic

For now I see way to use before_save hook to create queue and need stop save because, updating will in background with job.

May be other way?

Ok, now that you mention Mass Update I can think of a better way.

Instead of going into a “Save” action and then trying to keep it from saving, just add a new action on that menu:

https://developer.sugarcrm.com/2010/11/22/howto-adding-your-own-listview-action-items/

You can call it “Deferred Save” or “Queued update” or whatever. Then you get to run your own code from your class, without hooks.

When you get it to work, please come back here and share your code. I believe Queued updates are a very nice feature to add to SuiteCRM mass actions. I found a request online for that feature in SugarCRM, dating from 2011.

First of all thanks for the help!

The queue is working fine, I checked.

I also added a custom button using this example http://www.jsmackin.co.uk/suitecrm/adding-a-button-to-the-list-view-in-suitecrm/

Here is another issue. With new button I can check/uncheck more then one record and it works, but when button pressed there is no form there like mass update form, so on my new script I have only checked record ids without any other values. New problem is to get form wich will be usued with new button where I can put same values to update checked records.

I’d love to continue helping, but I’m afraid I don’t know the answer…