Important Notes
The samples and information below is provided without a warranty of any kind. This post is for informational purposes and coresystems ag assumes no responsibility for errors or omissions in the information provided.
Purpose
Attached is 1 rule that will ask the user if he wants to allow a change in currency or not. This can help to prevent changing a currency to "All Currencies" which is not reversable.
The rule is a good example how to create a messagebox with two buttons with which the user can choose how to proceed.
Requirements
The sample requires coresuite Version 3.50 or higher, and SAP Business One 8.8 or higher.
Procedure to use this small solution
- Download the attached file FAQ_10148_Decide_if_currency_should_be_changed.cocu
- Import in SAP Business One via > Administration > Add-Ons > coresuite customize > Import / Export > Import rules. In the message box, select “All Active”. Click on “Import”.
- Open an existing Business Partner in SAP Business One which does not have "All Currencies" set
- Change the currency of the Business Partner to "All currencies"
- In the System Message box "Do you want to change the business partner currency?" select "No" and see that the currency is still the original currency.
- Change the currency of the Business Partner again to "All Currencies"
- In the System Message box "Do you want to change the business partner currency?" select "Yes" and see that the currency has changed to "All Currencies".
Procedure to adjust this small solution
The main reason to publish this rules is to provide a sample of a message box with the two buttons with which the user can choose how to proceed. When adjusting the rule it is suggestion to do the main logic after the definition of the message box where now is the comment "// return true and allow the currency to change".
Preview Sample (Optimizer Rule C#):
string ruleName = pVal.RuleInfo.RuleName.ToString();
string errorMessage = "Error in Optimizer Rule '" + ruleName + "'";
string askMessage = "Do you want to change the business partner currency?";
string cancel = "No";
string ok = "Yes";
try
{
//StatusBar.WriteWarning("DEBUG - Rule: " + ruleName + " was triggered.");
// Ask if the action should be executed
SwissAddonFramework.UI.Dialogs.MessageBox.Buttons btnClick;
// The strings are defined in the parameters above. The default button is the cancel button
btnClick = SwissAddonFramework.UI.Dialogs.MessageBox.Show(askMessage, ok, cancel, SwissAddonFramework.UI.Dialogs.MessageBox.Buttons.Button2);
if (btnClick == SwissAddonFramework.UI.Dialogs.MessageBox.Buttons.Button2){
// User clicked on "NO" > end the process and return false to cancel the action
return false;
}
// return true and allow the currency to change
return true;
}
catch(System.Exception ex)
{
StatusBar.WriteError(errorMessage + ": " + ex.Message);
Debug.WriteMessage(errorMessage + ": " + ex.Message, Debug.DebugLevel.Exception);
}
return true;
Comments
0 comments
Article is closed for comments.