Page 1 of 1

Plugin help. Move BO lines to new order when processed

PostPosted: Fri Jul 01, 2022 10:50 am
by DannyC
I've knocked up a plugin which moves any backordered lines to a new sales order (as a Reserve Order) when the current snapshot is processed, i.e snap 1 as it will process to closed.

I basically ripped the guts out of the standard plugin Move Outstanding Amounts to New Order which is fired by a button. Mine is fired by processing.

It works a treat aside from an error I get at the very end "Object reference not set to an instance of an object". Normally I can work out what causes the error & the resolution.
But in this case I've stepped through the code with the VS debugger & still can't locate the cause. I have also disabled all other plugins, no luck there either.
I thought I'd chuck the plugin over to the Jiwa brains trust to see what can be done to stop the error.

Re: Plugin help. Move BO lines to new order when processed

PostPosted: Fri Jul 01, 2022 11:47 am
by Mike.Sheen
I got no such error in SR12.

This is what I did in demo data:

1. Created a new sales order for debtor 1002 - Arthur Creams
2. Added the items 1171 and 1172 to the order. 1171 had backorder quantity of 1, 1172 had no backorders
3. Saved the sales order
4. Processed the sales order - no error reported and 1171 on the order now shows as quantity ordered 0.
5. Navigated next to the next order which was created - has part 1171 on it, quantity ordered 1, quantity backordered 1.

If you can get the error reliably in demo data, please provide exact steps to reproduce similar to the above.

EDIT: Now I am getting the error when processing - it may be occurring only after the 2nd time processing?

Re: Plugin help. Move BO lines to new order when processed  Topic is solved

PostPosted: Fri Jul 01, 2022 12:09 pm
by Mike.Sheen
Fixed plugin attached.

I just had to remove where you were performing a .Commit and also your .Rollback.

Because you are not starting the SQL transaction, our sales order business logic is, you should not be committing or rolling back transactions. Only if you create the transaction should your plugin be handling that.

The plugin you based this off, Move Outstanding Amounts to New Order, DOES create a new transaction - so it commit's and rolls back - but you commented out in your plugin the creating of the transaction but not the commit and rollback.

Re: Plugin help. Move BO lines to new order when processed

PostPosted: Mon Jul 04, 2022 11:13 am
by DannyC
Thanks Mike.