David Crewe Ltd

Kofax Consultancy

KTM Document Routing - easier than you might think!

Batch routing in this article refers to:

1. The ability to route batches dynamically - skipping unnecessary workflow queues for example.

2. The ability to split a single batch into multiple batches – confident documents routed into a separate batch for example.

3. A combination of the 2 features above – routing confident documents past validation, but allowing other documents to go to validation for example.

The way in which these are accomplished in Kofax Capture and in KTM differs – although there is some overlap.

In essence with Kofax Capture this sort of functionality is achieved through custom components – Workflow Agents and/or Custom Modules. There is no way to add this sort of functionality into the basic batch class configuration.

In KTM however, some functionality is built in to the internal scripting environment which allows us to design some quite complex batch routing rules within our KTM project script – with no need for external code (although this can of course also be used).

Below we show you how easy it is to add some custom batch routing to a KTM project – and provide some code you can copy & paste to get you started.

We will show how you can do the following:

- Split a batch by document count.

- Split a batch by document type.

You can then add your own criteria to customise for your specific requirements.

So how does it work?

Document Routing in KTM makes use of XValues. These are custom values used to transfer information between KC and KTM.

We need to set some XValues at the batch (RootFolder) and document (XDocument) level. More information can be found in this Kofax Knowledgebase Article and also in the KTM documentation under Document Routing.

At the RootFolder level we will create XValues that KC can read and which tell KC to create new batches.

At the XDocument level we set XValues to tell KC which batch each document belongs to.

All of our scripts will be at the Project level in KTM. We will create two custom routines which will allow us to perform batch splitting by number of documents or by class, and call these from the Batch_Close event. The code below is very generic, and could be used as a starting point in any KTM project.

We need to copy & paste the two custom routines to the Project level script. The code for these can be copied from:



SplitBatchByNumberOfDocuments allows you to specify how many documents should be in each batch. So if you specified 5, and scanned an original batch of 20 documents, you would end up with 4 batches - each with 5 documents.

SplitBatchByClass allows you to create a batch per class. So in the project shown above where we have Northwest and TriSpectrum, if we scanned an original batch which had both classes, we would end up with 2 batches – one would contain all the Northwest documents and the other would have all the TriSpectrum documents.

In both cases at Batch_Close we loop through all of the documents in the batch (RootFolder), and where necessary - number of documents or new class - we create markers (XValues at the RootFolder level) to tell KC to create a new batch. We then set a marker (XValue at the XDocument level) to tell KC which batch to move this document into.

Once the routines are added, we can edit the Batch_Close event to call whichever method we want to use.

You can determine when the splitting occurs. In the examples above we are running in KTM Server, but you could also run after KTM Validation or any other KTM module. You would need to amend the Batch_Close script with one of the values in the table below to apply splitting after a different module.

Once the scripts are all added, and amended if required, you need to synchronise the KTM project to the batch class and re-publish.

After running the batch through KTM Server (or possibly another module if you amended the script) you will see the results in batch manager. In the screenshot below 8 documents were scanned and split into batches with a maximum of 3 documents.

Once you have this working, you can edit and change the test/split criteria as required. It is intended only as a starting point…

You can download a simple batch class and KTM project with the scripts in this article here.

If you would like assistance or advice on any KTM Scripting issues, feel free to Contact Us.

If you don't have the time or skills to write your own code, check out our KTM Script Utility which allows you to add complex functionality to your KTM scripts in minutes with only minimal coding required.

If you don’t use KTM, but still need some batch routing functionality added to your system, check out our easyBatchSplitter, or our collection of Workflow Agents.

Note: Ensure that you test any scripts thoroughly in a development environment before use in production. Ensure a thorough understanding of any other scripts used in your KTM project, in case they are not compatible with the functionality shown in this article.

 Back to blog list