Get a Data Directive to Only Run From a Scheduled Task

I’m trying to get a DD to run only when the data change is initiated by a scheduled task (Mass Credit Information Update). I can set a condition for a specific Assembly or Process ID in the callClientContext, but I can’t figure out what to use for a scheduled process. Any other ideas?

You can schedule the process with a specific user account then trigger the BPM depending the user.

1 Like

Put a standard data directive on Ice.SysAgentSched
The condition should look like:
At least one updated row
The ttSysAgentSched.SchedDesc = “Name of your task as it shows in task monitor”
The ttSysAgentSched.LastRunOn has been changed from any to another
After the condition, you can add whatever logic you want.

If you have multiple companies make sure that the logic takes that into account. By default it will run in the company that the agent task user was last logged into. You can counter this by using TemporarySession in the BPM to change the company context

1 Like

I thought of that but it’s possible for a user to run the process manually and not just the scheduled task and I would ideally like to cover that possibility. But a Security Group would probably cover all realistic scenarios. Thanks so much!

Be careful with Data Directives on SysAgentSched. When the Task Agent updates that Table (LastRunOn field), the User in Scope is the User on the Task Agent and the Company in Scope is the last company the Task Agent User actually logged in to.

3 Likes

The way you get around this:

using (CallContext.Current.TemporarySessionCreator.SetCompanyID("COMPANY").Create())
  {
  <logic>
  }
3 Likes

We had been using this method successfully until we went to ‘multi-company’. (10.2.200.400).
I made the changes suggested here- if I change the ‘next run date’ manually in the maintenance screen
my code runs perfectly (data-directive on SysAgentSched).

However when that date is changed by the Sys Agent my code does not run- it seems like the .Update data directive is ignored- note: user on the task agent is “manager”-does “manager” need some security rights to allow the data directive to fire properly?

Hi @fuji36,
You got any solution? because it’s same for me my code is also not working when system is updating next Run.

regards,
Moawiz Ali

Your profile version says 10.2.600 - if that is true - use Functions and schedule. If not, can you post your condition and code?

1 Like

If you cannot use Functions (version) and User Process Scheduler is not in your future, here are a few tips for achieving this:

  1. Create empty Process Set (Set to all Companies)
  2. Schedule the Process Set recurring to the Schedule of your choice. Note the scheduling description
  3. Add data directive as Standard to SysAgentSched
  4. Add condition using LastRunOn changed from any to another and SchedDesc = value from step 2
  5. Now add your code but keep these guidelines in mind
    The callContextClient.CurrentCompany will obviously be empty so avoid using
    The Session.CompanyID will be the company that the system agent account was last logged into.
    So you can set a Temporary Company to make sure this processes for the correct company
using (CallContext.Current.TemporarySessionCreator.SetCompanyID("**COMPANY**").Create())
  {
   // Keep in mind Session.CompanyID does not change within this
  // You can reference CallContext.Current.TemporarySessionCreator.Settings.CompanyID for queries or anything requiring Company
  }
1 Like

Hi @danbedwards
I am doing exactly same way, it’s working when I updated tim or anything on scheduler manually but when system is updated next run time only at that time my bpm is not doing anything.
I never used functions can you please direct me to any link from where I can learn functions.
Regards,
Moawiz Ali