Rule on Data View

I need to create a Rule on 2 conditions on a Data View. I have tried using the Rule Wizard but it only has one condition available to choose from how would I do two conditions.
My Data View: GS_Order_Detail_DataView
Conditions: if GS_EditComplete_c = True and if tbOrderChecklistTrueFalse.Text = “False”
Then hide gbHidePricing.

I have this code so far and it is not working at all.

	{
		// Description: EditingNotComplete
		// **** begin autogenerated code ****
		RuleAction[] ruleActions = new RuleAction[0];
		// Create RowRule and add to the EpiDataView.
		// Dummy Context Object
		object contextObject = null;
		RowRule rrCreateRowRuleGS_Order_Detail_DataViewOrderHed_GS_EditComplete_cEquals_False = new RowRule("GS_Order_Detail_DataView.OrderHed_GS_EditComplete_c", RuleCondition.Equals, false, new RowRuleActionDelegate2(this.GS_Order_Detail_DataViewOrderHed_GS_EditComplete_cEqualsFalse_CustomRuleAction), contextObject);
		((EpiDataView)(this.oTrans.EpiDataViews["GS_Order_Detail_DataView"])).AddRowRule(rrCreateRowRuleGS_Order_Detail_DataViewOrderHed_GS_EditComplete_cEquals_False);
		// **** end autogenerated code ****
	}

	private void GS_Order_Detail_DataViewOrderHed_GS_EditComplete_cEqualsFalse_CustomRuleAction(Ice.Lib.ExtendedProps.RowRuleDelegateArgs args)
	{
		// ** RowRuleDelegateArgs Properties: args.Arg1, args.Arg2, args.Context, args.Row
		// ** put custom Rule Action logic here
		//MessageBox.Show("Only Edit Complete False");
	
		if(tbOrderChecklistTrueFalse.Text == "False" && tbOrderEditComplete.Text == "False")
		{
			MessageBox.Show("Checklist and EditComplete are False");
			gbHidePricing.Visible = true;
		}
		else
		{
			MessageBox.Show("Checklist and EditComplete are not Complete");
			gbHidePricing.Visible = true;
		}
	
	}

I’m not sure that you want the 0 in the following line:
RuleAction[] ruleActions = new RuleAction[0];

For multiple rules, I created two rule action arrays. The following code is working for us. Note that it is also using a custom Control Setting:

		// Set the conditional Row formatting
		ControlSettings StyleGreen =  new ControlSettings();
		StyleGreen.BackColor = System.Drawing.Color.FromArgb(100,200,100); 
		// Setup the Actions (styles) to apply
		RuleAction RowActionStyleGreen = RuleAction.AddRowSettings(this.oTrans, "UnassignedAllergens", true, StyleGreen);
		RuleAction[] NewRuleActionsGreen = new RuleAction[] {
				RowActionStyleGreen };
		// Create RowRule and add to the EpiDataView.
		RowRule NewRowRuleGreen = new RowRule("UnassignedAllergens.AttrCode", RuleCondition.Equals, "A-FREE", NewRuleActionsGreen);
		((EpiDataView)(this.oTrans.EpiDataViews["UnassignedAllergens"])).AddRowRule(NewRowRuleGreen);
		//this.gridAssignedAllergens.DisplayLayout.Bands[0].Columns["AssignedAllergens.AttrCode"].Width = 100;
		
		// Set the conditional Row formatting
		ControlSettings StyleBrown =  new ControlSettings();
		StyleBrown.BackColor = System.Drawing.Color.FromArgb(220,190,150); 
		// Setup the Actions (styles) to apply
		RuleAction RowActionStyleBrown = RuleAction.AddRowSettings(this.oTrans, "UnassignedAllergens", true,StyleBrown);
		RuleAction[] RuleActionsBrown = new RuleAction[] {
				RowActionStyleBrown };
		// Create RowRule and add to the EpiDataView.
		RowRule NewRowRuleBrown = new RowRule("UnassignedAllergens.AttrCode", RuleCondition.Equals, "ORGANIC", RuleActionsBrown);
		((EpiDataView)(this.oTrans.EpiDataViews["UnassignedAllergens"])).AddRowRule(NewRowRuleBrown);
		//this.gridAssignedAllergens.DisplayLayout.Bands[0].Columns["AssignedAllergens.AttrCode"].Width = 100;

Note: There may be a more efficient way to do this.

Shannon, Your code is configured using an Action Delegate but what you need is a standard Action with a Condition Delegate.

Go into the Rule Wizard Sheet and create a new Rule.
Rule Description: Whatever
Rule View: Your Order Detail View
Select View: Your Order Detail View
Select Field: Your Edit Complete column name

Rule Condition: CustomCondition (This will create a Condition Delegate)

Rule Value: True

Add to Conditions.

Create standard Rule Action to Hide the Pricing.
Add to Actions.
Update Code.

Go to the Script Editor and you will see where the code was created for a Condition Delegate. You will need to code both conditions in the delegate and then set the return value to True or False. If set True, the Action will occur.

3 Likes

Thank you @Rich for these instructions. They are exactly what I needed! :grinning:

Hi Guys, its it possible one rule to rule them all? I am trying to set a color for a particular condition base on two fields but I want that my method works for every view in my dashboard. Do you know a way to do this?

Thanks a lot here is my code.

	private bool ValidateSDRevisionReason(object arg1,object arg2)
{
	if (arg1 !=null && arg2 !=null)
	{
		arg1.ToString();
		arg2.ToString();
	}
	return false;
}

private void CreateRowRuleV_AXIS_SOShopDrawingUpd_1View1_SDRevision_Reason_Electrical()
{
	ControlSettings customColorSetting = new ControlSettings();
	customColorSetting.BackColor = System.Drawing.Color.Orange;
	// Description: Electrical1
	// **** begin autogenerated code ****
	object contextObject = null;
	RuleAction errorV_AXIS_SOShopDrawingUpd_1View1_RowAction = RuleAction.AddRowSettings(this.oTrans, "V_AXIS_SOShopDrawingUpd_1View1", false, customColorSetting);
	RuleAction[] ruleActions = new RuleAction[] {
			errorV_AXIS_SOShopDrawingUpd_1View1_RowAction};
	// Create RowRule and add to the EpiDataView.
	RowRule rrCreateRowRuleV_AXIS_SOShopDrawingUpd_1View1OrderDtl_ShortChar10Equals_080 = new RowRule(null, UserNotAllowedToJobClosed, contextObject, ruleActions);
	((EpiDataView)(this.oTrans.EpiDataViews["V_AXIS_SOShopDrawingUpd_1View1"])).AddRowRule(rrCreateRowRuleV_AXIS_SOShopDrawingUpd_1View1OrderDtl_ShortChar10Equals_080);
	// **** end autogenerated code ****
}