Auto Import Scripting

Auto import scripting allows manipulation of the file list passed to the auto import routine. Use these script methods to either sort or filter the list of files prior to import. Auto Import scripting methods are contained within one class, the AutoImportFileSetScript class.

AutoImportFileSetScript Class

In addition to the IsScriptMethodEnabled and EnableUnrestrictedCode methods, the AutoImportFileSetScript class contains the following:

SortFileSet Method

SortFileSet returns an array of string values representing the sorted file list. This method is called before the files are filtered and queued for import. On the Auto Import Settings screen, the setting labeled Auto Import File Sorting Method controls file sorting by creation date, modified date and file name. To sort using SortFileSort method, select the “Sort using Script” setting, check the "Filter file set by script" checkbox, and then press the Open Script Editor button:

Parameters:

Directions Parameter Type Editable Descriptions
IN files array of string no the unsorted list of files to import

Return:

The sorted file list as an array of string values.

Example – Sort the files by file extension and file name:
public virtual string[] SortFileSet(string[] files)
{
	try
	{
		//Convert the array to a list
		var fileList = files.ToList();
		//Use LINQ to sort first by extension, then by file name
		var ordered = fileList.OrderBy(f => Path.GetExtension(f))
							  .ThenBy(f => Path.GetFileName(f));
		//Convert the results back to a string array and return
		return ordered.ToArray();
	}
	catch (Exception exception)
	{
		base.ProcessException(exception);
		return null;
	}
}

FilterFileSet Method

FilterFileSet returns either true or false. This method is called after sorting and before files are queued for import. Use FilterFileSet to remove files from the list before importing begins. Return true to signal the batch that files have been processed. Return false to reject the entire list of files.

Parameters:

Direction Parameter Type Description
IN/OUT files array of string Contains the list of fully-qualified file names detected for queuing. Alter this list to control which files will be queued for import.

Return:

True or false.

Example 1 – Remove any file with an extension containing “doc”:
public virtual bool FilterFileSet(ref string[] files)
{
	try
	{
	//Set up a new list to store the fltered list of files
	List<string> filteredFiles = new List<string>();
	foreach(string file in files)
	{
		//If the file extension doesn't contain "doc", add the file to the list
		if(!Path.GetExtension(file).ToLower().Contains("doc"))
			{
			filteredFiles.Add(file);
			}
	}
	//Set files to the new filtered list of files
	files = filteredFiles.ToArray();
	//Return true to let PSI:Capture know all went well
	return true;
	}
	catch (Exception exception)
	{
		base.ProcessException(exception);
		return false;
	}
}
Example 2 - Prevents automation from queueing files between the hours 6AM and 8PM:
public virtual bool FilterFileSet(ref string[] files)
{
    try
    {
        // Obtain the current hour in 24-hour format (0-23)
        int currentHour = DateTime.Now.Hour;
        //
        // Check if the current hour is between 6:00 AM and 8:00 PM.
        // If so, prevent files from queuing.
        if(currentHour >= 6 && currentHour <= 20)
            return false; // prevent auto import from running
        else
            return true;  // allow auto import to run
    }
    catch (Exception exception)
    {
        base.ProcessException(exception);
        return false;
    }
}

NOTE: When limiting the time window for auto import, consideration should be given to the daily file volume. The script prevents files from queueing for auto import. If file volumes are high, a large number of files can build up in the monitored locations. Once auto import is allowed to process files again, it will queue all available files which in turn can lead to a very large, unwieldy batch. When limiting the auto import time window, consider limiting the number of files that are included in each batch via the Max Imported Files Per Batch option.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.