Page 1 of 1

Prevent SO Save Event

PostPosted: Tue Sep 15, 2020 4:36 pm
by Riyaz
Hi There

We have a custom plugin wherein we need to prevent the save event at certain times, the code is running at save start and also initiating cancel exception, but it still seems to save the SO. Can you pls advise, have attached the plugin for your reference

Re: Prevent SO Save Event

PostPosted: Tue Sep 15, 2020 5:44 pm
by Mike.Sheen
That works for me.

I had to comment out a bunch of code to try and repro the issue, however - because your plugin refers to custom fields not present in the plugin you provided.

Attached is the modified version of your plugin I tested with - and using that when I save a sales order, it prompts me if I want to continue saving and when I answer 'No', it does not save and returns to the sales order in edit mode.

Re: Prevent SO Save Event  Topic is solved

PostPosted: Thu Sep 17, 2020 3:45 pm
by Riyaz
Hi Mike

Thanks for your reply, actually, there was another exception after this where the problem was, found the cause, ok now, issue was that was inside a try catch block so it was getting caught. Thanks for your support.

Re: Prevent SO Save Event

PostPosted: Fri Sep 18, 2020 2:15 pm
by Mike.Sheen
Riyaz wrote:Hi Mike

Thanks for your reply, actually, there was another exception after this where the problem was, found the cause, ok now, issue was that was inside a try catch block so it was getting caught. Thanks for your support.


Ahh, I see that now - the problem code was below where I was looking - I just tested the first scenario I came across where you were performing a throw.

If I looked through all your code, I would have found where you had a throw inside a try catch and the catch swallowed the exception inside a handler of the sales order SaveStart event - which is where your problem was.

If we had just the relevant code to the problem inside the plugin, that would have saved us all a lot of time. A lesson learned for the next time!