Prevent subsequent SAP events
Thomas Bühler
Hi all,
I have the following issue:
I am trying to add a optimizer rule that should recalculate the total amount for an order due to specific UDFs we are using.
So actually that was easy to calculate and set the value to the total amount cell of the matrix in the purchase form after the user has chosen a new article.
The problem I have is to deal with predefined SAP B1 events on that form. After I have set the cell value my script ends. SAP itself now recognizes the change and will do a recalculation of the sales discount field automatically (which is not desired from my side).
So simple question is: how can I prevent subsequent SAP events in my rule script? I have tried to return "false" instead of "true" but this doesn't work at all.
Here are some details where you can reproduce my situation:
Create a new optimizer rule with the following details:
Typ=CSCODE
FormTyp = 142
ItemUID=38
Column=1,11,14,15
EventTyp=Value Changed
Before Event=false
Inner Event=true
Here is the C# script (reduced for simplicity:)
try
{
Matrix m = Matrix.GetFromUID(pVal.Form, "38");
double totalAmountTest = 1000.0; //of course there is a more complicated calculation in my script, this is just for testing purposes
m.SetValue("21", pVal.Row - 1, totalAmountTest.ToString(), true);
//just click on first cell
m.Columns["1"].Cells[pVal.Row - 1].Click(SwissAddonFramework.UI.Components.MatrixColumn.ClickTypes.Regular, SwissAddonFramework.UI.Components.MatrixColumn.Modifier.None);
return true;
}
catch(System.Exception ex) // Error handling
{
MessageBox.Show("Error: " + ex.Message, "OK");
return false;
}
By the way I am using the latest downloadable modules (V4) inside SAP 9.0 PL04.
Thanks and best regards,
Thomas
Anders Olsson
Hi Thomas,
To stop any action (incl SAP) you must do that in the Before Event. In your case Before Validate would be a good place. When before is false, it doesn't matter if you return true or false because the action has already taken place.
The problem with your example is that if you do that you will cancel BOTH the user input (validation will fail, making it impossible to leave the field) and the SAP scripts. Therefore it will not work.
The short answer is, it cannot be done.
Regards,
Anders
Please sign in to leave a comment.
Comments
0 comments