Introduction

Although the Import Flat FileClosed The Import Flat File tool imports a delimited or fixed width file from disk into BPA Platform, extracts the file contents including any file properties, and outputs it as either a recordset or as XML. and Import XML DocumentClosed The Import XML Document tool imports an XML document to be used and processed by other task steps. To validate the XML documents at runtime, you can either import an XML schema file (XSD), infer from an existing XML document, or manually construct the XSD. tools support wildcards when searching for the import file, it's not obvious how to force the tools to process all found files. This articles describes how to build a task to do just that.

How Does BPA Platform Import at the Moment?

When specifying the file to import, you can use * (all) and ? (specifically here) wildcards:

Import Flat File - General Tab - Wildcard Example

The above example searches for all text files starting with ORDER. Currently, if more than one file matches the search query, the oldest file is imported and processed. As none of the Input tools use the Memory featureClosed Memory definitions specify the data, generated by a task at run-time, to be memorised. You can save memorised data in an internal Repository, in an ODBC or OLEDB data source, or in an OLEDB data source via a stored procedure., you can not force the Import tool to search and import again unless the task is re-run.

Required Tools

The tools required for this specific purpose include:

Import Flat File or Import XML Document — To import the files
File ManagementClosed Use the File Management tool to carry out a number of automated actions on single or multiple files — move, copy, rename, and delete — either locally or across the network. Uploads to and downloads from an FTP server are also supported. — To move the files from "Processing" to "Done"
DecisionClosed The Decision tool is used to control the flow of a task process, based on the result of one or more expressions. The decision works by testing a sequence of Boolean (true/false) conditions in turn until an expression returns true. When a true condition is returned then that particular branch of the process is followed. — To determine whether there are more files needing importing
Call TaskClosed The Call Task tool is used to trigger an external task to run. Using variables, BPA Platform data can be passed between the two tasks at run-time, if required. — To restart the task when it has finished processing the current file
ScheduleClosed The Schedule tool is used to trigger a task to run based on a date and time schedule. Any number of Schedule steps can be created for a task. — To run the task at set times

Other tools may be involved in your task but these fulfil this specific scenario.

Prerequisites

In addition to the folder where the import files are waiting for processing, create a folder to move the imported file to when the task is finished.

Both folders must be accessible by the BPA Platform client running the task.

Extending the Task

We have a basic task where we are importing a file, formatting, and saving it:

Import Flat File > Run Crystal Report > Save File

The Import Flat File step is using a wildcard to locate the files to be imported. However, this task only imports and processes the first file it finds.

To ensure that all files found are processed, do the following:

Move the Imported File to "Done"

To ensure we do not import the same file each time the task is run, we need to move it out of the monitored folder. We use the File Management tool to do this:

  1. Add the File Management tool to the task.
  2. Enter a unique Name for this step and consume the file details from the Import step.
  3. Go to the Main tab and set this step to move the imported file to the "done" folder created earlier.
  4. Go to the Options tab and set the required error handling options.
  5. Click OK to save and close the step.
  6. Change the task flow so this step is the last step of the task.

Checking for Additional Matching Files

We use the Decision tool to check whether the Import tool has found any more files to process and if not, terminate the task:

  1. Add a Decision step to the task and Name it Any More Files?.
  2. Add a new decision branch that continues the task if the Import tool has found matching files.
  3. Add a Run VBScriptClosed The Run VBScript tool is used to create a task step that runs a Visual Basic Script using data produced by other steps in the task. step to the task; no configuration is required for this step other than naming it End Task.
  4. Add another decision branch to your Any More Files? step that goes to the new Run VBScript step if the Import tool hasn't found any matching files.
  5. Change the flow of your task so that the Decision step is AFTER the Import step:

    Import to Decision

Restart the Task

The task flow is now such that if there's a matching file to import, it is dealt with; if no matching files, then the task ends. But how do we force the task to restart to look for more files? A Call Task step is needed to "call" the task once it has completed. First, we need to create a global connection to the folder containing the task — even if you have placed your tasks in the top-level Tasks folder, you must still create the connection.

Creating a Dedicated Call Task User

We must create a dedicated user for the Call Task step to use — this prevents clashes with other user accounts that may be logged into the BPA Platform client at the same time:

  1. Save and close the task.
  2. From the resources tree, right-click on Users and select New User.
  3. Enter calltask as the User name.
  4. Enable BPA Platform Authentication and enter a password that adheres to your organisation's security policies. Confirm the password.
  5. Go to the Server Roles tab and ensure all server roles are cleared.
  6. Click OK to save and close the user.

Creating the Global Connection to the Task Folder

Now we can create the global connection to the relevant task folder:

  1. From the resources tree, go to System > Tools > Execute > Call Task.
  2. Click Add.
  3. Enter a Connection Name of Import Tasks.
  4. As the tasks are run on the same computer as this BPA Platform client, enter localhost as the Server.
  5. Enter the calltask user's details in Username and Password.
  6. Go to the Folder tab and select the folder containing these tasks.

Call Task - Create Global Task Connection

Adding the Call Task Step

Finally, we add a Call Task step to the task.

  1. Reopen the task.
  2. Add a Call Task step to the task design area.
  3. Name this step Call Task - Go Back to Beginning.
  4. As we're not using any data from other steps in the task, we can go straight to the Connection tab.
  5. Choose the connection created previously.
  6. Go to the Mapping tab.
  7. From the Object drop-down, select the Import Flat File step.
  8. From the Operation drop-down, select Queue — this operation calls the task selected for Object. As this task does not depend on any external data, it can start while the current task run completes.
  9. Go to the Options tab and set the required error handling options.
  10. Click OK to save and close the step.
  11. Change the task flow so this step is the last step of the task.

Final Adjustment to the Import Step

As your task is now going to check for matching files , we must adjust the Import step so that if a matching file is not found, the task continues onto the Decision step which handles terminating the task gracefully should it need to.

Note that the following procedure applies to both the Import Flat File and Import XML Document tools:

  1. Open the Import step and go to the Options tab.
  2. Ensure that If no files could be processed or found matching the source file name has Continue enabled.
  3. Click OK to save and close the step.
  4. Save the task.

Automatically Running the Task

Currently, the task can only be initiated manually (Tasks toolbar > Queue Now BPA Platform - Tasks - Queue Now). At the time of writing, BPA Platform cannot start tasks based on new files being added to folders. Instead, we use the Schedule tool to periodically run the task.

  1. Add a Schedule step to the task.
  2. In the Main tab, configure the required run schedule.
  3. Click OK to save and close the step.
  4. Change the task flow so that this is the first step of the task:

Schedule > Import Flat File > File Management - Move to Processing > Run Crystal Report > Save File > File Management - Move to Done

The Schedule step has no impact on the Call Task step's ability to restart the task; any manual task initiation, whether by a Call Task step or by selecting Queue Now BPA Platform - Tasks - Queue Now in the Task menu, always overrides an existing Schedule step.

For more information about each individual tool used in this article, refer to the Tool-Specific Guides section.