Linking User Name to UserID field in data directive

I am working on a fairly simple data directive to alert members of our team automatically when a forecast order has been placed. It is working currently however the email is a bit more difficult to read than id like when including the data fields. Particularly the created by and Custnum fields. Our user ID’s are fairly different from peoples’ actual names so for the users receiving this email they wouldn’t be able to easily determine who created entry. And then it would just be nice to have the customer name display instead of the customer number.

I’ve searched around and I saw a bit about maybe using the invoke BO method to link those fields to the fields i’m looking for in other tables but I couldn’t quite make that work. I’ve seen other instances of users using code to do this but I’m not particularly good at programming.

1 Like

There’s a few ways to slice this.

  • LINQ query within the BPM. You join the SysUserFile table to your dataset and output the desired columns. I’d do it in code, but I believe you can do something similar with a fill table by query widget.
  • Scheduled function that aggregates recent changes. This is my go-to method.
  • Create a BAQ with all of your fields, and execute it via the DynamicQuery BO. This gets a little hairy from a data directive. You’d probably want to use a post-proc BPM on Erp.BO.Forecast.Update instead.

Frankly, going through the update method is better in several ways. You really only want to use a data directive if it’s something like Job records, which can be created and modified by any one of a half dozen modules and you want your rules applied consistently.

2 Likes

After posting I dug a bit more into the invoke BO method I originally mentioned and was able to get it working. I was able to invoke the GetByID method and output the table’s as variables (it was the return value binding that I was originally missing). This has worked pretty well after a few tests.

I am curious why this may not be a good method to approach this problem though. The scheduled function to aggregate recent changes sounds interesting, would you be able to elaborate on that?

From @josecgomez:

2 Likes

Data directives should be a method of last resort because of how often they can be triggered. It’s kind of a blunt hammer. It will do the thing you want. It will do it often. Possibly too often.

GetByID should also be approached with caution since it grabs everything related to the record. I’ve seen huge payloads returned on Job calls, for example. A query is better unless you will be updating a record and actually need everything.

Now, is any of that an issue on this specific implementation? Probably not. However, if you put a data directive on PartTran that then called JobEntry.GetByID you’d notice a performance impact. It’s a not-great practice that you can get away with on small, infrequently used modules, but will hang you if tried on bigger, busier parts of the system.

Functions are a way to centralize complicated customizations in one place, and reduce the amount of stuff in BPM’s spread across the system. You can also schedule them using the Task Agent. I’d search the forum for more information. They’re powerful, therefore hard to summarize.

3 Likes

I did initially start with a method directive instead of a data directive. Using the Forecast.Update BO however I found that the two conditions I tried to use (The specified field has been changed from any to another, and there is at least one added row to the specified table) did not trigger the email to send upon adding a new forecast entry.

1 Like

I would use a Linq query to look up the field you want is way cheaper than a Bo call

5 Likes

I will look into this option as wells as the function option John recommended. This could be a topic for another thread but is there any decent education material, preferrably free, on programming with specific focus on Epicor. I can write C# code but am unfamiliar with creating code to be used in Epicor. If there is any documentation or maybe even a few example tutorials that someone has links to I would greatly appreciate it. Thanks for all of the help everyone!

1 Like

I’m afk today @klincecum don’t you have a few genitive indices we can point him to and some links

I know the Epicor help has the customization guide and the programmers guide

And ofcoirse the forum here

1 Like

I was too until just now, but I’ll see what I can drag up.

Generally Helpful for New & Old Epicor Programmers

Code Syntax Highlighting in Posts

Genitive Indicis (Index)

Let’s share useful Functions! - Sharing Is Caring :slight_smile:

Let’s share useful (Programming) Resources

Kinetic Code Camp - Bring your skills, or lack thereof… :dumpster_fire:

Experts Corner

Code Review & Sharing

That should get you started.

3 Likes

I have a sample email that is used on a standard data directive that I will cleanup and post.

2 Likes

Dude… thank you so much this is extremely helpful.

2 Likes

I have these on a standard data directive, so it is after the write, so the user does not have to wait for it to happen. If your environment works with sending Async (some are finicky) then it is even less of a load.
Email Credit Hold Sample.cs (3.2 KB)

1 Like

You cleanup code fast.

1 Like

LOL. Ok I made the sample a few years ago and wanted to be sure it did have too many really bad habits in it. It has a few, but eh.

1 Like

Yeah I posted one not long ago, and just had to profusely apologize in advance and beg for forgiveness. It was too much to rewrite just to get the point across.

1 Like