Control State After UD Form Save

Skip the wizard entirely write your own. Epicor uses them extensively in the way demonstrated below. In all Part Entry source has over 1000 lines of row rules to control all of the read only jazz on conditions. That’s their preferred way of handling that stuff.

All done in UD01 for demonstration

public class Script
{
	private EpiDataView edvUD01;

	public void InitializeCustomCode()
	{
		this.edvUD01 = ((EpiDataView)(this.oTrans.EpiDataViews["UD01"]));
		SetupRowRules();
	}

	public void DestroyCustomCode()
	{
		this.edvUD01 = null;
	}

	void SetupRowRules()
	{
		RuleAction rSChar1 = RuleAction.AddControlSettings(oTrans, "UD01.ShortChar01", SettingStyle.Disabled);
		RuleAction rChar2 = RuleAction.AddControlSettings(oTrans, "UD01.Character02", SettingStyle.Disabled);

		RowRule RowModAdded = new RowRule("RowMod", RuleCondition.NotEqual, "A", new RuleAction[] { rSChar1, rChar2 });
		edvUD01.AddRowRule(RowModAdded);
	}
}
2 Likes

@Banderson / @jgiese.wci:

So, I tried both examples provided yesterday and neither seem to work. The closest I got was modifying Joshua’s example merely to fire off the desired condition upon saving a record, then attempting to adjust a textbox control property within the met-condition code block.

Here’s what I tried to do:

For some odd reason, the desired condition is detected upon record save - BUT - I cannot seem to alter any control property. I had tried to alter:

  • txtFieldName.IsEpiReadOnly = true
  • txtFieldName.ReadOnly = true
  • txtFieldName.Enabled = false
  • txtFieldName.Visible = false

None of these respond when inserted into the “if (bolRowModAStatus = false)” code block. Not sure why.


I see that Joshua has just posted a different approach, so I’m going to try that and report back to you guys in a short while.

I’m grateful that both of you have been very patient with me and more than willing to lend a hand – thanks so much.

@Banderson / @jgiese.wci :

Joshua’s example appears to work well. Below is an example the expected behavior, where all controls are disabled upon record save:

(Note for those who may have searched this topic): This method is limited to controls bound to the data view only. So, if you have additional custom controls such as buttons which are not part of the data view, they will not be inclusive to the Row Rule action. Just a point of interest there.

This definitely does the job and also serves as a visual indicator that the record was saved successfully.

Thanks very much for sticking with me on this. I learned quite a bit here, including the reinforcement of the idea that data-specific controls are bound to the data view and should always be modified from the data view itself. This is the “EpiMagic™” that @josecgomez has routinely mentioned in the past.

Thanks again, gentlemen, for your help.

Aaaaaaannnnd… wouldn’t you know it… I uncovered the reason why my previous code wasn’t working (you’ll love this, I promise).

Here was the salient conditional where I couldn’t modify any control properties beneath it:

if (bolRowModAStatus = false)

Notice anything suspicious?

Yep - it should have been written correctly as:

if (bolRowModAStatus == false)

Out of mere curiosity, I’m going to go back and see if that original approach would have worked… because I’m a glutton for self-flagellation. :confounded:

1 Like

Confirmed that I can successully modify control properties based on that original evaluation of the conditional. Does this mean I should switch back to that approach?

Absolutely not.

Joshua’s example is the correct method to use for data-specific controls bound to a data view. So, I’ve left that code in place. For non-bound control objects, such as buttons that I might need to disable, or hide, the EpiViewNotification method (with correctly-written conditional evaluations [cough-cough]) would be a good choice to include in this case.

For a quick and dirty route you should be able to do this:

//Global
EpiTextBox keybox;
//Initialize
keybox = (EpiTextBox)csm.GetNativeControlReference("your guid to your key control");
keybox.PropertyChanged += new PropertyChangedEventHandler(PropChange);


//Destroy
keybox.PropertyChanged -= new PropertyChangedEventHandler(PropChange);
	
    }

private void PropChange(object o, EventArgs a)
{
EpiGroupBox box = (EpiGroupBox)csm.GetNativeControlReference("your guid to your group control with all your UD controls");  //you could instead ref the controls individually, you can access direct because they arent system controls
box.ReadOnly = ((EpiTextBox)o).ReadOnly;
}


1 Like

The rule action can be a function (like what the wizard creates) that contains code handling stuff that is not dataview bound.