Forum Discussion

yhussien's avatar
yhussien
New Contributor
2 years ago

How to save updated data in SaveDataEventHandler

Hello OneStream Community,

I am using the SaveDataEventHandler to validate a cell amount being saved. Depending on certain conditions I update the amount in the “args.NewDataCell.cellAmount” and set “args.Cancel = False”.

Instead of the modified amount in “args.NewDataCell.cellAmount” the original amount entered gets saved.

 

In the snippet of the code below, a sample error log output when a user inputs 4.3466 in a form would be:

Amount Before = 4.3466

Amount After = 4.35

But the saved amount in the form will be 4.3466.

----Snippet Start-----

BRapi.ErrorLog.LogMessage(si,"Amount Before = " & args.NewDataCell.CellAmount)
args.NewDataCell.CellAmount = Math.Round(args.NewDataCell.CellAmount, 2, MidpointRounding.AwayFromZero)
BRapi.ErrorLog.LogMessage(si,"Amount After = " & args.NewDataCell.CellAmount)
args.Cancel = False

----Snippet End-----

Please advise.

3 Replies

  • Henning's avatar
    Henning
    Valued Contributor II

    Hi, apologies, but this is not the answer you are looking for. I recommend not using any rules to round data in the system. Rounding data should be done in and for reporting purposes only. I, personally, have not come across a use case where I thought rounding in rules is ok (though such a use case may exist, of course). 

    In addition to that, save data event handler have to be used with great care as they may have an adverse impact on performance.

    • yhussien's avatar
      yhussien
      New Contributor

      Henning,

      Thank you for your response. I appreciate your comment. This is a unique request from the client that we have to implement. Also, we trap validation errors and show popup messages from the save event handler on other applications without a considerable performance hit.

      If you know of a way how we can save the altered data, it would be much appreciated.

  • Hi, I agree with Henning this will have impact on performance as every time any user submits data this event handler will execute the code.

    If you want to round specific intersections, I will suggest using a finance rule.

    Thanks, Omkareshwar

    Archetype Consulting