Checkbox click event

I have added a checkbox to the Job Close form to indicate the job has been cancelled. I would like to have the date stored in the Job Completed Date field when the new box is checked. I have tried setting the read only property for the date box to be false when the flag is checked. I have noticed that if I put it in the CheckedChanged event it fires twice, where the first time the date field is enabled but the second time it goes back to being disabled. I have tried putting the code in several of the events (Click, CheckValueChanged, AfterFieldChange), but none of them enable the field.

What is the proper click event to get the Job Complete Date field enabled (not read only)?

If you bind that field to something, you can then use a BPM to do that on Update.

If you want to use custom code this works for me

	private void MyCheckBox_CheckedChanged(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		if(this.MyCheckBox.Checked == true){
			this.MyTextBox.ReadOnly = false;
		}
		if(this.MyCheckBox.Checked == false){
			this.MyTextBox.ReadOnly = true;
		}
	}

That is the event that fires twice. I have a message box that shows it firing inside each part of the if statement and it pops up twice. The first time I can see the date enabled but the second time it becomes disabled again. How do I keep it from either firing the second time or not changing the read only back to true?

I would like the user to enter the date, not just set it to today (which I assume would be the BPM solution).

Can you post your code

It looks pretty much just like yoursā€¦

	public Ice.Lib.Framework.EpiDateTimeEditor CompDate;

	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
		CompDate = (Ice.Lib.Framework.EpiDateTimeEditor)csm.GetNativeControlReference("c957d618-0644-4126-ab4f-375c4fb0f31b");
		this.epiCheckBoxC1.Click += new System.EventHandler(this.epiCheckBoxC1_Click);
		this.epiCheckBoxC1.CheckedValueChanged += new System.EventHandler(this.epiCheckBoxC1_CheckedValueChanged);
		this.epiCheckBoxC1.CheckedChanged += new System.EventHandler(this.epiCheckBoxC1_CheckedChanged);
		// End Wizard Added Custom Method Calls
	}

	private void epiCheckBoxC1_CheckedChanged(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		if (epiCheckBoxC1.Checked == true)
		{
			MessageBox.Show("true");	
			CompDate.ReadOnly = false;
		}
		else
		{		
			MessageBox.Show("false");
			CompDate.ReadOnly = true;	
		}
	}

Your code is working just fine on my end. It stays enabled after the two message boxes pop up and disables properly too.

I notice you defined all the events at the top. Maybe start from a clean customization and try the ā€œCheckChangedā€ event.

I deleted the customization and put it back with just the CheckChanged event but I still have the same issue. It keeps setting the Completed date field back to read-only. Guess it is time for BPM code to force todayā€™s date in even though that is not what I want.

For some reason this Date field is stumping me. I gave up on trying to enable the CompletedDate field since it would never enable it (I did delete the form customization and only added the CheckChanged event but it still would not enable it). I am trying the BPM route. I have tried post and pre processing on the JobClosing.PreCloseJob event (see attached design). I traced the events when checking the completed box to get to the JobClosing.PreCloseJob event. In each case I was not able to get the date to save. I manually updated the jobHead when attempting post-processing and just setting the field in the pre-processing. I can see my messages come out with the proper data but it isnā€™t saving the data to the field or database.

Is there some sort of Epicor control that is stopping me from update the JobCompletedDate field?

Pre-Processing:

Post-Processing code:

{  

var j = Db.JobHead.Where (e=>e.JobNum == jobNum);

foreach (var job in j)
{
  job.JobCompletionDate = DateTime.Today;
  this.PublishInfoMessage("job set " +  jobNum + " " + job.JobCompletionDate ,Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"", "");   

}
Db.Validate();
txScope.Complete();
}

I apologize I didnā€™t notice you were using the native control for the Completion date.
Iā€™m not sure if it is all forms or not, but it seems like you canā€™t change the state of some native controls.

How about hiding( or putting off screen) the native control for the Completion date and adding a new DataTimeEditor control bound to the Completion date. Then use the ā€œCheckedChangedā€ event.

Thatā€™s what I did and the checkbox is changing its state correctly.

As for the closing date itself. That might be trickier, as there might be an Epicor BO that updates that field. I would have to run a trace to see.

You can use a BPM form. Which is a pop up window when the BPM fires. You can default information as well. Here is an example of a BPM form; you can see there is information flowing into the form that the user can update. You can also make the fields required and even customize the form as needed. Lots of possibilities.

I second this suggestion. Create a UD JobCancelled field in the DB. Then run a BPM on Job Updates that will run the normal JobClosing methods. I would not just try to set the field on JobHeader. Use the BOā€™s.

Iā€™ll also add, from personal experience, that sometimes you have to use UpdateExt instead of Update to prep jobs for closing automatically.

We are not closing the jobs at this point. All I am trying to do is add a cancelled flag but use the Completed date.

That being said, I am giving up and adding a UD date for the cancelled so I will not change the Completed date. Itā€™s not worth the hassle.

1 Like

Regardless, there are specific BOā€™s that handle JobComplete and JobClosing. Itā€™s not something you can just set in Job Entry, which is why you keep running into issues. You also seem to be trying to set the date field, but not the associated JobComplete boolean field. If memory servers, you really just need to set JobHead.JobComplete to true, and the BOā€™s will tag the date.

Youā€™ll have more success working with the flow of the system than trying to hack around it.

I was trying to use my own flag independent of the close or complete flag but I was trying to use the Complete Date field which does not appear possible. I am creating a date field to go with the cancelled field I have added so I can set it. Guess sometimes you canā€™t hijack fields.

sounds like a good plan.

For the BPM, please try and use the tt vs db. You will get caught with errors trying to update a record that was already updated.

I have added a UD field for the date instead of using the Completed Date. Unfortunately I still canā€™t turn on and off the read only for that field within the Job Complete/Close form. I am giving up on allowing the user to set the date field and am setting it to Today in the BPM. That works fine. Now my issue is if the uncheck the box I want to clear the date, but not matter what I try it gives me errors that I canā€™t set the date to null. I have tried to fake it out by creating a date variable in the BPM, setting that to null, then setting my Cancel date to the variable but that doesnā€™t work either. Nothing seems to let me wipe out the date.

How do I get the date to clear so that if they uncheck the box it will clear out the date?

Donā€™t give up.

Donā€™t bind your checkbox to anything.

Use a Before Adapter Method to pull the values you need and shove them in the dataview
before update.

Here is where things get weird. I have tried using the Before Adapter Method for both Select (JobHead) and Close (JobClosing) and neither one are firing. I have put in message boxes to show me they are getting into the code and I get no messages at all.

I am fine with the BPM route if I can just get the date field to clear if the user unchecks the custom checkbox. How do I set the date to null or empty string without it giving the error that I canā€™t set the field to null?

You could use a string field instead. May need some conversions to use it properly down the line though.