RowRule With Condition

Hello All,

I have a row rule where I would like to highlight the row red if the QuoteMtl.EstUnitCost is different from a query result.

I can’t seem to pass the current part number that the row rule is executing on… Is this even possible?

I would like the row rule to compare the estunitcost with the result passed back from my method GetLastCost which runs a BAQ based on the part supplied from the row rule.

// **************************************************
// Custom code for QuoteForm
// Created: 5/17/2021 8:40:40 AM
// **************************************************

extern alias Erp_Contracts_BO_QuoteDtlSearch;
extern alias Erp_Contracts_BO_Quote;
extern alias Erp_Contracts_BO_Customer;
extern alias Erp_Contracts_BO_AlternatePart;
extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_Vendor;
extern alias Erp_Contracts_BO_VendorPPSearch;
extern alias Erp_Contracts_BO_ShipTo;
extern alias Erp_Adapters_PartCostSearch;
extern alias Ice_Contracts_BO_DynamicQuery;
extern alias Ice_Contracts_Lib_BOReader;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Ice.BO;

public class Script
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

		//private EpiDataView edvJobMtl;
	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **

	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
		//this.edvJobMtl = ((EpiDataView)(this.oTrans.EpiDataViews["JobMtl"]));
		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls

	public void DestroyCustomCode()
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		//this.edvJobMtl = null;
		// End Wizard Added Object Disposal
		// Begin Custom Code Disposal

		// End Custom Code Disposal

	private decimal GetLastCost(string PartNum)
		decimal LastCost = 0;
		//string vPartNum = String.Empty;

			DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
					QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("QuoteLastCost");
					qeds.ExecutionParameter.AddExecutionParameterRow("PartNum", PartNum, "nvarchar", false, Guid.NewGuid(),"A");
					dqa.ExecuteByID("QuoteLastCost", qeds);
	    			if (dqa.QueryResults.Tables[0].Rows.Count > 0)
						LastCost = Convert.ToDecimal(dqa.QueryResults.Tables[0].Rows[0]["PartCost_LastMaterialCost"]);
			return 0;

	private void CreateRowRuleJobMtlEstUnitCostNotEqual_Constant_CompanyID()
		// Description: test
		// **** begin autogenerated code ****
		RuleAction errorJobMtl_EstMtlUnitCost = RuleAction.AddControlSettings(this.oTrans, "JobMtl.EstMtlUnitCost", SettingStyle.Error);
		RuleAction[] ruleActions = new RuleAction[] {
		// Create RowRule and add to the EpiDataView.
		RowRule rrCreateRowRuleJobMtlEstUnitCostNotEqual_Constant_CompanyID = new RowRule("JobMtl.EstUnitCost", RuleCondition.NotEqual, GetLastCost(((EpiDataView)this.oTrans.EpiDataViews["JobMtl"]).dataView[((EpiDataView)this.oTrans.EpiDataViews["JobMtl"]).Row]["PartNum"].ToString())  , ruleActions);
		// **** end autogenerated code ****



I found something in the customization guide on a custom row rule condition… I am now trying to see if I can access the fields I need for my method to go and get the last cost.

private void CreateRowRuleJobMtlEstUnitCostCustomCondition_5()
		// Description: test4
		// **** begin autogenerated code ****
		RuleAction errorJobMtl_EstUnitCost = RuleAction.AddControlSettings(this.oTrans, "JobMtl.EstUnitCost", SettingStyle.Error);
		RuleAction[] ruleActions = new RuleAction[] {
		// Create RowRule and add to the EpiDataView.
		RowRule rrCreateRowRuleJobMtlEstUnitCostCustomCondition_5 = new RowRule("JobMtl.EstUnitCost", new RowRuleConditionDelegate2(this.JobMtlEstUnitCost5_CustomRuleCondition), 5, ruleActions);
		// **** end autogenerated code ****
	private bool JobMtlEstUnitCost5_CustomRuleCondition(Ice.Lib.ExtendedProps.RowRuleDelegateArgs args)
		bool result = false;
		// ** RowRuleDelegateArgs Properties: args.Arg1, args.Arg2, args.Context, args.Row
		// ** put Row Rule condition evaluation logic here

		return result;

You can see the place where it says args.ARg1, args.Arg2, and Args.Row…

I think If I can somehow figure out the Args.Row object and get to the PartNumber field in that I will be golden.

EDIT: you can use Args.Row[“PartNum”] or whatever other field you need. It ended up working great for me.