---
description: New scheduled job platform that allows for easy customization
---

# Changes to scheduled jobs!

As of version 16 we've made important changes to how scheduled jobs are created and deployed. Scheduled jobs now use the recently introduced service hoster in order to have full customization support. The previous scheduled jobs have been moved from the now defunct `BusinessFunctions` class into the apropriately named `busScheduledJobs` business object.

Adding a custom scheduled job is as easy as customizing the `busScheduledJobs` business object and adding a new method that accepts no parameters and returns `void`.&#x20;

{% hint style="info" %}
Enabling customizations for a server mandant can be done by editing the tlx.ini file where the server has been installed and adding a 'CustomPath' key with the value pointing to a custom path directory, just like we do to client mandants.

Example:&#x20;

```ini
# ...
[ServicePorts]
  tlsvc = 50516
[Mandant/001]
  Mandant = Neo16
  DmsMailImport = Off
  DMSImportConfiguration = 
  ConnectionString = Provider=SAOLEDB.17;ENG=local-17;DBN=Neo16;Links=tcpip(Host=localhost);Downlevel=TRUE
  Credentials = Yq2AIIl+GMGH+rZUozxerg==
  # We apply this custom path to the server mandant called Neo16
  CustomPath = C:\Customizations\CustomServer16
# ...
```
{% endhint %}

Here is an example we used to have in the documentation for custom scheduled jobs, adapted to version 16. In order to create a new custom scheduled job, first create a new customization from TimeLine Developer.

<figure><img src="https://2522353545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXf5GuikRIHooatf_sm%2Fuploads%2FB8QEMVzIXisUec8kCkH2%2Fimage.png?alt=media&#x26;token=d5a6763b-0c37-4787-9ef4-95e10349fe75" alt=""><figcaption><p>A new customization for v16</p></figcaption></figure>

The next step is to customize the busScheduledJobs business object and add our new logic.

<figure><img src="https://2522353545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXf5GuikRIHooatf_sm%2Fuploads%2FnZqpNklQdpq9ys92Gus1%2Fimage.png?alt=media&#x26;token=a86211a1-9e0c-4687-bce8-2f3da0c4dfd0" alt=""><figcaption><p>Customizing the busScheduledJobs object</p></figcaption></figure>

To ensure our custom methods are picked up by the service hoster we need to make sure we edit the server tlx.ini to add the custom path to our server mandant (as shown at the top of this page). **Please make sure you restart the service hoster service in order for this change to take effect!**

We can easily add a new custom method that can be invoked via the scheduled jobs mechanism by writing a non-static public method that returns void and has no parameters.

### Generating reports from server-side scheduled jobs

{% hint style="info" %}
Make sure you reference the TimeLine.Report assembly
{% endhint %}

<pre class="language-csharp"><code class="lang-csharp"><strong>public void ReportExportTest()
</strong>{
    TranslationManager.Instance.LoadCurrentCulture();
    
    var rep = new TimeLine.Report.TLListAndLabel();
    xSqlArgs args = new TimeLine.Framework.Data.xSqlArgs();
    
    rep.DoPreview("rptBeleg02", args, null, "Beleg02", null, "c:\\TMP", "ExportTest", "pdf", null, null, null, null);
}
</code></pre>

If everything is set up correctly you should be able to see the custom added method in the scheduled job configurator dropdown:

<figure><img src="https://2522353545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXf5GuikRIHooatf_sm%2Fuploads%2FGPdpxlrhXUB6d6YRVFWE%2Fimage.png?alt=media&#x26;token=c2d86eb1-ad87-4feb-b243-5423901e4553" alt=""><figcaption><p>The custom method appears in the scheduled jobs configurator</p></figcaption></figure>

For the above example to work you need to have the Beleg02.lst report in your server installation reports directory. A succesful job run should produce the expected results:

<figure><img src="https://2522353545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXf5GuikRIHooatf_sm%2Fuploads%2FwdbsCmIFcnunlZfRsb85%2Fimage.png?alt=media&#x26;token=9bd25418-6d3d-4ef4-9832-7ba9c2d751d9" alt=""><figcaption><p>Succesful custom job run log output</p></figcaption></figure>

<figure><img src="https://2522353545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXf5GuikRIHooatf_sm%2Fuploads%2FF44lHpireiuXxAnLjYTh%2Fimage.png?alt=media&#x26;token=a6930b05-ad22-4ad8-b7ee-64aa5ed25674" alt=""><figcaption><p>The generated report</p></figcaption></figure>



{% hint style="warning" %}
Please note that only calls to the busScheduledJobs.Log method actually get logged into the jobs' log file - any other output (like calls to the TimeLine Framework Log static class will be written into the log associated with the ServerBusinessObjects service hosted by the Service Hoster. In this case, this file is located at **TimeLine Server 16.0\Logs\ServiceHoster\ServerBusinessObjects\_Neo16** where Neo16 is the mandant name this was running under.
{% endhint %}
