Page 1 of 1

Changing SaveErroredSets in plugin code

PostPosted: Tue Nov 28, 2023 1:55 pm
by DannyC
I have a scenario where I want to swap the setting GLParams SaveErroredSets from true to false and back again willy nilly. Just for some testing - wont be used for production.

This is from a StockTransfer.
Assume that the setting is true normally. I want to set it to false, attempt to activate the transfer and if it errors for whatever reason, capture the reason in the event log.

Can I use this code to set it one way or another? Temporarily using VB .Net for this plugin!
Code: Select all
Try
   stockTransfer.Manager.Database.ReadSysData("GLParams", "SaveErroredSets", false)
   stockTransfer.ActivateRecord()
Catch ex As Exception
   LogToEventLog(String.Format("Error during activating Stock Transfer '{0}', error '{1}'", sTransferNo, ex.Message), System.Diagnostics.EventLogEntryType.Error)   
   stockTransfer.Manager.Database.ReadSysData("GLParams", "SaveErroredSets", true)
End Try



Re: Changing SaveErroredSets in plugin code  Topic is solved

PostPosted: Tue Nov 28, 2023 4:06 pm
by Mike.Sheen
DannyC wrote:Can I use this code to set it one way or another?


That code isn't even trying to set the system setting. It's reading it, but not setting it. Use SaveSysData to set the value of a system setting, not ReadSysData.

So, you want to use ReadSysData to get the current value, then use SaveSysData to set it to true, then perform your stockTransfer.ActivateRecord() and then in the finally use SaveSysData to set it back to what it was.

This will probably be all you need for the stock transfer, but be aware that other business logic might not use your updated system setting without some coercion. Stock transfer will create a new Journal Set object upon activation of the stock transfer - and so the system setting is read at that point.

Other business logic may create the journal set object at the time of their own instantiation, and so won't re-read the system settings on activate and thus will not get your updated system setting - in which case you need to set the business logic JournalSet.SystemSetting.SaveErroredSets property yourself instead of using Manager.Database.SaveSysData... but that may not be a problem for you if you're solely interested in changing this system setting for just Stock Transfers.