Hello and thanks in advance from C# Noviceland. Been using and working with Epicor since v8 and am just now biting the bullet to learn a bit more about UI customizations and C#.
My objective here is to hide a field on a form based on the Current Company value. My first attempts were centered around using the Load Form Event, and I got as far as being able to detect the current company in an if statement and show a message. After poking around a bit here and elsewhere, I thought perhaps using a Rule Wizard would be a better approach–there seems to be a preference for using the Rule Wizard in such cases, though I am not sure why.
What I soon discovered is that if I created a rule that detected the current company (using the CallContextClientData view), I could not make an action that involves the field I want to hide–RevisonNum on the Order Detail view. So, I tried creating two rules, one for using CallContextClientData and the other using Order Detail and thought I might be able to mix and match in the script editor.
Here is what gets stubbed in from the Rule Wizard…
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete ‘Begin/End Wizard Added Variable Initialization’ lines **
// Begin Wizard Added Variable Initialization
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
CreateRowRuleOrderDtlPOLineEquals_5();
CreateRowRuleCallContextClientDataCurrentCompanyEquals_FOO();
// End Wizard Added Custom Method Calls
}
(no change on public void DestroyCustomCode()
private void CreateRowRuleOrderDtlPOLineEquals_5()
{
// Description: HidePartRev
// **** begin autogenerated code ****
RuleAction invisibleOrderDtl_RevisionNum = RuleAction.AddControlSettings(this.oTrans, "OrderDtl.RevisionNum", SettingStyle.Invisible);
RuleAction[] ruleActions = new RuleAction[] {
invisibleOrderDtl_RevisionNum};
// Create RowRule and add to the EpiDataView.
RowRule rrCreateRowRuleOrderDtlPOLineEquals_5 = new RowRule("OrderDtl.POLine", RuleCondition.Equals, 5, ruleActions);
((EpiDataView)(this.oTrans.EpiDataViews["OrderDtl"])).AddRowRule(rrCreateRowRuleOrderDtlPOLineEquals_5);
// **** end autogenerated code ****
}
private void CreateRowRuleCallContextClientDataCurrentCompanyEquals_FOO()
{
// Description: CurrentCompany
// **** begin autogenerated code ****
RuleAction errorCallContextClientData_CurrentUserId = RuleAction.AddControlSettings(this.oTrans, "CallContextClientData.CurrentUserId", SettingStyle.Error);
RuleAction[] ruleActions = new RuleAction[] {
errorCallContextClientData_CurrentUserId};
// Create RowRule and add to the EpiDataView.
RowRule rrCreateRowRuleCallContextClientDataCurrentCompanyEquals_FOO = new RowRule("CallContextClientData.CurrentCompany", RuleCondition.Equals, "FOO", ruleActions);
((EpiDataView)(this.oTrans.EpiDataViews["CallContextClientData"])).AddRowRule(rrCreateRowRuleCallContextClientDataCurrentCompanyEquals_FOO);
// **** end autogenerated code ****
}
And here is my failed attempt at accomplishing my objective…
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete ‘Begin/End Wizard Added Variable Initialization’ lines **
// Begin Wizard Added Variable Initialization
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
CreateRowRuleCallContextClientDataCurrentCompanyEquals_FOO();
// End Wizard Added Custom Method Calls
}
(no change on public void DestroyCustomCode()
private void CreateRowRuleCallContextClientDataCurrentCompanyEquals_FOO()
{
// Description: CurrentCompany
// **** begin autogenerated code ****
RuleAction invisibleOrderDtl_RevisionNum = RuleAction.AddControlSettings(this.oTrans, "OrderDtl.RevisionNum", SettingStyle.Invisible);
RuleAction[] ruleActions = new RuleAction[] {
invisibleOrderDtl_RevisionNum};
// Create RowRule and add to the EpiDataView.
RowRule rrCreateRowRuleCallContextClientDataCurrentCompanyEquals_FOO = new RowRule("CallContextClientData.CurrentCompany", RuleCondition.Equals, "FOO", ruleActions);
((EpiDataView)(this.oTrans.EpiDataViews["CallContextClientData"])).AddRowRule(rrCreateRowRuleCallContextClientDataCurrentCompanyEquals_FOO);
// **** end autogenerated code ****
}
The code tests out in the Script Editor, but I get an error when I open the form:
Error Detail
Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Invalid RuleActions - can only set ControlSettings in current view
Program: CommonLanguageRuntimeLibrary
Method: InvokeMethod
I realize that I am crossing streams here and that I may be completely on the wrong track–my SQL/Procedural coding experience is a bit lost in this object-oriented world.
Any help pointing me in the right direction would be much appreciated.