Search code examples
kofax

How to create an image import job using KTA SDK?


I am trying to create a job using SDK. Simple job with send email activity work like a charm!

But when I try to create a job with variables input folder to import few images it doesn't work at all. Am I missing very trivial settings ?

My process has classification activity & extraction activities Variables : DefaultImportFolder

FYI : My process works fine if I set import settings -> import sources. That tells me there is no issue with my process process Smile. But when I try to run through console app with dynamic variables, it doesn't work.

Following is my sample code. Any help?

ProcessIdentity processIdentity = new ProcessIdentity
            {
                Name = "SDK TestProcess"
            };

            var jobService = new TotalAgility.Sdk.JobService();
            JobInitialization jobInitialization = new JobInitialization();

            InputVariableCollection variablesCollections = new InputVariableCollection();
            InputVariable inputVariable = new InputVariable
            {
                Id = "DefaultImportFolder",
                Value = @"\\FolderPath",
            };
            variablesCollections.Add(inputVariable);

            inputVariable = new InputVariable
            {
                Id = "ExportSuccess",
                Value = "true"
            };
            variablesCollections.Add(inputVariable);

            var createJobAndProgress = jobService.CreateJob(sessionId, processIdentity, jobInitialization);

            Console.WriteLine($"Job ID {createJobAndProgress.Id}");

As Suggested by Steve, tried with WithDocuments method Still no luck .....

JobWithDocumentsInitialization jobWithDocsInitialization = new JobWithDocumentsInitialization();

                Agility.Sdk.Model.Capture.RuntimeDocumentCollection documentsCollection = new Agility.Sdk.Model.Capture.RuntimeDocumentCollection();

                Agility.Sdk.Model.Capture.RuntimeDocument runtimeDoc = new Agility.Sdk.Model.Capture.RuntimeDocument
                {
                    FilePath = @"FolderPath\abc.tif",

                };

                documentsCollection.Add(runtimeDoc);

                jobWithDocsInitialization.Documents = documentsCollection;


                var jobIdentity = jobService.CreateJobWithDocuments(sessionId, processIdentity, jobWithDocsInitialization);
                Console.WriteLine($"Job ID {jobIdentity.Id}");

Solution

  • A folder variable represents a reference to a folder that already exists in the KTA database, so you can't just set a file path to the variable. When you create a job via an import source, it is creating the folder and documents as part of creating the job.

    To do the same in your code, you would use one of the "WithDocuments" APIs such as CreateJobWithDocuments which has parammeters specific to importing documents into the process, including by file path.

    As discussed in this other answer (Kofax TotalAgility Send a PDF Document to Jobs Queue (KTA)), you may want to look at the sample code that is included with the product (that most people don't realize is available), and also look at other API functions for more context on the parameters needed for the "WithDocuments" APIs mentioned above.