How to add date to UD field triggered by a checkbox


I am trying to get the current date to go to a UD field when a box is checked and saved.
What I tried was a Data Directive - In-Transaction on table: FSCallhd.
I added a condition of: ‘ttFSCallhd.Approved_c field has been changed from false to true’.
I then did an ‘Execute Custom Code’ with this in it:

foreach (var x in (from y in Db.FSCallhd
where y.Company == Session.CompanyID
select y))
x.Approved_Date_c = DateTime.Now;

I realize that I need to narrow it down in the where statement but I have no idea what to put there.

I would think something like: && y.CallNum == ???
??? should be some way to access the current CallNum.

I am still learning Custom Code as you can tell and would appreciate if someone could fill in the blank.
And maybe explain how you found it for my continuing education???

I really appreciate this site. It has been wonderful for helping.

The loop you have is going to update all records and I assume you are only looking to update the current record where the checkbox was checked? You should be looping through ttFSCallHd and setting the field.

I understand that it will update all records for that company, I am not sure how to get it to update the specific record that called it. Do you have any specific ideas?

there is a ttFSCallhd table available in the DD that contains the current record you are working on, you should be able to join to that record. Further more, if this is happening in an In-Tran directive you can do this without writing any code.
Simply use the Set Field option
If you want to better understand BPMs and such I recommend a full and thorough read of the Customization Guide, the ICE Tools Guide and the Programmers Guide all available in EpicWeb

1 Like

By using ttFSCallHd instead of Db.FSCallhd will update only the record that initiated the call. You would not need to use custom code for this as well unless you had other reasons.

My reasons were two-fold…

  1. I am trying to teach myself custom code as that seems the most resilient.
  2. I didn’t think of the set field. :disappointed:

The set field worked fine but I am going to try the custom code just for my education.

I thank both of you for your help. Please be patient with me as I have to learn this in between my other duties at this company…

1 Like


I changed the reference from Db.FSCallhd to ttFSCallhd and tested. Looks like it worked fine.

Now if I had tried to build this in the Standard Data Directive, this would not have worked, right?

Would there have been a custom code that would have worked there or should it only have been done as ‘In_Transaction’?


You are correct. The only thing I would add, and this is just my preference, would be to use a method directive when you can. A pre-processing method directive would work with the same custom code.

Why is that a preference?
Maybe you can answer another question I have then.
How can I get a list of all the Method Directives created by our company?
In Data directive, I can do a search all, then sort each column one at a time to get the active ones at the top. That way I can see what data directives are being used.
I couldn’t figure an easy way to do that in method directives.

In the method directive search you can select “Search By Directive” and leave the Group = Any. This will return all the method directives that have been created. Enabled is another thing.


@danbedwards can you elaborate on why this is your preference? Curious as to what you see, I always lean to Data Directives since they guarantee no matter the incoming method that they’ll get executed. Granted Method Directives have its place, but for a default field I generally lean towards DD.

Corrrect, Standard Directives are meant to be read only and run on “post” processing

Like Jose, the Data Directive is great so I don’t miss a Method Directive. However, I try to keep the code in Data Directives simple since they are called anytime Epicor touches that table. If not careful, one can really ruin the performance of the system.

Mark W.

1 Like