Using a Task Agent Schedule to run a BPM on a schedule

The topic came up elsewhere so I thought I’d make a general post for those who want to see how it works. My apologies if this is already a topic elsewhere - I did not see a similar post in my cursory search.

Premise - how to run a BPM (usually a chunk of custom code) on a schedule with no add-ons to the basic system such as the User Process Scheduler add on.

Solution - using the Task Agent schedules, you can create a schedule that has no tasks, but can trigger a BPM that is itself selective in identifying if it should run or not. I’ve provided images that should explain it all. Every time the execution date/time triggers, it updates to the next interval and THAT is the change that triggers the BPM(Data Directive).

My example runs a chunk of custom code to retrieve currency conversion rates from the OANDA website.

First, start with a schedule that has no tasks, but is named accordingly.

Second, create a Data Directive.

Third, set a conditional block that allows control over the execution of the DD. The first condition checks to see if this is the correct schedule to fire on, and the second condition makes sure the interval changed/expired and that it is time to fire the DD. The third condition allows me to control the run-state by using the enabled checkbox on the schedule rather than editing the DD directly.

Hopefully someone finds this useful and gets some mileage out of it!
Mike

19 Likes

@MikeGross Thanks for sharing! I was able to test this out on my own and able to run the BPM on a schedule!

1 Like

Just a couple old notes around this approach. The logged in company, if you have multiple companies, is important to remember when doing this and there is a way around it from this post.

1 Like

I’m trying this out now. Seems very cool to be able to launch BPM on a schedule. =)

Take a look at User Process Scheduler from Epicor if you want a nice solution for this as well. Or, in your version, you can schedule a Function to run on a schedule

2 Likes

Something that I’ve worked out… to do it in a Custom Code Widget without using a Condition Widget, you can use the code below, you will need to change the AgentSchedNum to match yours

bool sysAgent = ttSysAgentSched.Any(s => s.Updated() && ttSysAgentSched.Any(s1 => s1.Unchanged() && s1.SysRowID == s.SysRowID && s1.LastRunOn != s.LastRunOn && s.AgentSchedNum == 209860));
if (sysAgent == true)
{
 // Do your thang here
}
2 Likes

Hi MIke,

I know this is an older post, but here goes anyway.
We have been successfully using this type of procedure to kick off BPM code every day, we just recently added a patch and now we have issues. Our BPM fires off a ‘generate invoices from shipments’ business process, part of an AR Invoice automation project.

Does your ‘agent schedule’ show up in the System Monitory history after it runs?
There is something about the ‘company’ that the schedule runs in that is confusing us.

For instance, the sys monitor shows that our agent ran in company 'CANADA' even though , when I last created/altered the system agent, I was in our other company, the company that we want for the BPM.
When I altered the sys agent, I was not logged in as 'manager', should I have been?

  I remember seeing something about: The 'company' of the sys agent , when it runs , depends on the company that the user was logged into when last changing/setting the agent.

I’m not sure of course, but it does sound like someone altered the system agent when in the other company. Epicor retains the company context for a user from the first login, so whichever user is logging in as the system agent, it’s company context is the base/starting context for all the jobs. And for jobs that don’t allow you to specify company, it’s the default.

Have you signed back in as your Agent User and set the company context back to the proper company - and let the job run? Did that work?

This burnt me a few times way back when, so I have actually set up a SQL Job to run and force this back to the ‘primary’ company every morning at 1 AM just before a selection of company-specific Task Agent jobs run.

Disclaimer - this is not an Epicor sanctioned method for correcting this. Use at your own risk.

image

Thank you Mike, I will try that.

Hi,

This is nice option, but maybe someone can explain what could be that this works onprem automaticaly, but does not work on cloud. It does not trigger BPM, unless you change next run manualy :frowning:

@Justas you should have Functions in your version of Epicor which can be scheduled more easier than BPMs.

image

3 Likes

Because Epicor ERP started as an on-prem solution. As @Randy mentions, the EFx is a far more flexible solution. You can schedule them within Epicor, or if you have complicated time zone requirements, outside of Epicor. The EFx is the new and improved BPM. They are related but for these kinds of tasks, the Function is more appropriate.

3 Likes

Randy:

For this particular case, I am using 'auto-print' functionality in a standard data-directive, for Invoice Edit List creation- that 'block' (auto-print) is not available in the function designer, at least not in our version.

I am using functions to ‘generate shipments’ and ‘post AR invoices’.