Changing SaveErroredSets in plugin code  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Changing SaveErroredSets in plugin code

Postby DannyC » Tue Nov 28, 2023 1:55 pm

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


User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Changing SaveErroredSets in plugin code  Topic is solved

Postby Mike.Sheen » Tue Nov 28, 2023 4:06 pm

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.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 19 guests