Rule Wizard with %

I am trying to use Rule Wizard to create a rule that highlights the Qty Remaining field in Receipt Entry if (Qty Remaining / Qty Ordered) < 0.05. This meant to be a visual cue to the person in receiving that maybe they should mark it as Received and Complete if less than 5% of the quantity is missing.

But when I go into the Rule Wizard I can’t figure out a way to do LessThan a percentage of a field. I can only select LessThan the value of a field. Am I missing something or is there just not a way to do this in Rule Wizard?

A very round about way to do this would be to create a UD field and have a BPM update it with (Qty Remaining / Qty Ordered). Then run your Rule based on the UD field.

1 Like

Ok, so I did as you suggest. The BPM runs and updates the UD field, I can validate that with a BAQ. But the Rule Wizard isn’t highlighting the field like I expect it to. Did I do something wrong here?

Hi Aaron,
The Rule Wizard generates custom code (script editor), add some debugging messages there to see what’s going on.

Regards,

1 Like

Check if the control on the form is bound to the DB or a view. Try adding another Rule Action to highlight a control that you know should work.

Okay … I can duplicate the issue. An odd thing that happened, was after making the rule (rules condition my UD field < 0.05), it appears to have changed it to a view field, but without a view or field selected.

image

I deleted that rule and recreated it. Now it shows properly, and works.

image

FYI - If you have multiple rules you can set the order by re-arranging the order they are called in the InitializeCustomCode() function

Ex: In the following, the ...Equals_0 Warns the BidMargin_c field (sets to Red), and ...LessThanOrEqualTo_0_05sets it to Highlight (yellow)

		// Begin Wizard Added Custom Method Calls
		CreateRowRuleOrderHedBidMargin_cEquals_0();;
		CreateRowRuleOrderHedBidMargin_cLessThanOrEqualTo_0_05();;
		// End Wizard Added Custom Method Calls

The When zero it would show as yellow (not red), because the <=0.05 is processed after the zero check. Reorder them to like below to show yellow when <= to 0.05, and red when = 0.

		// Begin Wizard Added Custom Method Calls
		CreateRowRuleOrderHedBidMargin_cLessThanOrEqualTo_0_05();;
		CreateRowRuleOrderHedBidMargin_cEquals_0();;
		// End Wizard Added Custom Method Calls
2 Likes

So I had the same odd experience that even though I specified “Rule Value” it reverted to “View/Field” too. Deleting it and recreating it fixed the rule condition for me like it did for you.

So now that that is out of the way… well I’m still not seeing the field being highlighted. I’ve tried a few different fields but none of them seem to work. I am kind of wondering if the Receipt Entry / Line screen is using temp tables to display data rather than database fields, because if the database field is marked as highlighted but what is on the screen is data from a temp table, then it wouldn’t display, right? I’m not sure if my understanding of temp tables is correct. I mention this because in order to get the BPM to trigger I had to use the appropriate temp table.

I’m thinking that the rules use the temp table info. On my test (just setting the control of the UD field to Red when Zero, and Yellow when less than 0.05) the color changes as soon as I change the value of the filed - this is prior to any DB updates.

Are you showing the UD field? Just as a debugging tool, to see if it is updating when you think it is.

Edit

I changed my testing to be more like yours. I have three fields (all UD fields of OrderHead):

  • BidRevenue_c
  • BidMargin_c
  • BidMarginPct_c

The last one is calculated by a BPM and updated when the record is saved.

The control showing BidMarginPct_c doesn’t change, and the row rule doesn’t fire, until I save.

1 Like

I was able to get the Row Rule to fire by updating the UD field on the form (using oTrans), in real time (not waiting for a save).

1 Like

So if I set the UD field to display on the form and use Rule Wizard to highlight that UD field, then the rule works fine. But I can’t get it to highlight other fields on the form. Is that maybe a limitation, that I can’t apply highlight rules to Epicor created fields? I vaguely remember someone telling me that sometimes you need to hide the Epicor field on the form then add a new one overtop of it, and bind it to the same database field so that you can work with it more easily. Is that valid?

This thing about oTrans updating in real time sounds wonderful. What is that and where can I find it? I haven’t heard of that before.

First off, the row rules should effect any control that is bound to the field specified in the Actions section. The controls that display the field may be bound to views instead of db tables (or temp tables holding intermediate info). So make sure the control you expect to highlight is actually bound to the DB and not a View.

I have two actions for a rule based on a UD field being less than 0.15

  • OrderHed.OrderNum to style Error
  • OrderHed.BidRevenue to style Warn

As you can see below,

  • The Epicor field OrderHed.OrderNum (1) is Red
  • The UD field OrderHed.BidRevenue_c (2) is Yellow

Because the Row rule is fro when OrderHed.BidMarginPct_c is < 0.15

So you can have the row rules affect builtin fields. (or at least I can)

Ah ok, I think that was it. The form fields that I am trying to highlight don’t seem bound to an actual table so it must be a view. That explains it. Thank you!

This thing about oTrans updating in real time sounds wonderful. What is that and where can I find it? I haven’t heard of that before.

Don’t get too excited, I may be using it wrong …

In that picture above, users enter Bid Revenue(2) and Bid Margin. Margin% (3) is calculated as BidMargin / BidRevenue * 100.

I originally had a BPM to calculate the Margin% and store it in the UD field (OrderHed.BidMarginPct_c). But that would only update when the order was saved - which was okay for us as we used those values for later reporting.

To make the contol showing BidMarginPct update when either of Bid Revenue or BidMargin changed, I made form events on their controls. The functions then calculated the value to be displayed in the Margin% control.

To update that control (and get the data into the temp table so it is written out as needed), I used the oTrans (which I don’t entirely understand). But the following works (and is apparently the best way to do it):

private void nedBidMargin_Leave(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		EpiDataView edv = (EpiDataView)oTrans.EpiDataViews["OrderHed"];
		decimal marginPct=(decimal)0.0;
		
		if((decimal)nedBidRevenue.Value == (decimal)0.0){
			marginPct = (decimal)0.0;
			}
		else{
			marginPct = (decimal)((decimal)nedBidMargin.Value / (decimal)nedBidRevenue.Value * (decimal)100.0);
			}

		edv.dataView[edv.Row]["BidMarginPct_c"]= Math.Round(marginPct,2);
		//oTrans.Update();
		//oTrans.Refresh();
	}

If I needed the changed value to be written right away, I’d un-comment the oTrans.Update() and oTrans.Refresh() lines. Just be aware, since the oTrans is referencing the OrderHead, the update will cause all OrderHed fields to update (as neccessary).

1 Like