Indexing - Data Record Processing Scripts

Use the methods in the DataRecordIndexingScript class to validate or change index filed values at the batch, folder or document level. Check the "Use custom scripts to populate and validate index fields" checkbox and press the Open Script Editor button.

 

 

DataRecordIndexingScript Class


For Batch Level

BatchDataRecordInitialize Method

The BatchDataRecordInitialize method is called in the Capture / Import module just after a batch is created. Use this script to pre-populate batch-level index fields.

 

Parameters:

 

Directions Parameter Type Descriptions
IN batch IBatch The current batch
dataRecord IDataRecord The record containing the batch-level index fields

 

Example – Initialize the batch-level index field BatchSource with the machine name, the date/time stamp in a particular format, and the words True or False to denote whether or not the batch was generated from auto recognition. Separate each value using the underscore character.
public virtual void BatchDataRecordInitialize(IBatch batch, IDataRecord dataRecord)
{
  try
  {
     dataRecord["BatchSource"].Value = 
         string.Format("{0}_{1}_{2}", System.Environment.MachineName,
                                      DateTime.Now.ToString("yyyyMMddHHmmss"),
                                      batch.AutoRecognitionBatch);
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
  }
}

 

BatchDataRecordIndexing Method

The BatchDataRecordIndexing method is called from the Create Batch dialog in the Capture / Import module when a batch is first created. It is also called in the Index module during auto indexing, just after lookups for the batch index fields complete. Use this method to verify and correct values before normal validation occurs.

 

Parameters:

 

Direction Parameter Type Description
IN batch IBatch The current batch
dataRecord IDataRecord The data record containing the batch-level index fields

 

Example – If batch index field BatchSource has no value, assign it the value of “DEFAULT”.
public virtual void BatchDataRecordIndexing(IBatch batch, IDataRecord dataRecord)
{
  try
  {
    if(dataRecord["BatchSource"].StringValue.Length == 0)
      dataRecord["BatchSource"].Value = "DEFAULT";
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
  }
} 

 

BatchDataRecordValidated Method

BatchDataRecordValidated is called after indexing processing and default validation of the batch record. It performs custom validation of all batch index fields. It is called from the following modules:

  • Auto import – at the start of document auto-processing



  • Capture/Import – when closing a batch
  • Index – at the start of auto-indexing and when closing a batch 
  • QA – at the start and end of QA auto-processing, and when closing a batch

It is also called whenever the user presses the Validate Batch icon, such as in the QA module screen to the right. 

Return true from this method to indicate the batch data record is valid, or false to indicate it invalid.

 

Parameters:

 

Direction Parameter Type Description
IN batch IBatch The current batch
dataRecord IDataRecord The data record containing the batch-level index fields
validate true/false True if the record is currently valid, false if it is not
IN/OUT validationMessage string A user-defined, custom validation message

 

Returns:

True or False

 

Example – Validate the value entered for the BoxNumber batch index field. Return false if the value is less than 999000 and document type name for the batch is “DisposalBoxes”. Also return a custom error message.
public virtual bool BatchDataRecordValidated(IBatch batch, IDataRecord dataRecord,
                                             bool valid, ref string validationMessage)
{
  try
  {
    // Validate the box number entered for the batch
    if(dataRecord["BoxNumber"].Value < 999000 && batch.DocumentType.Name == "DisposalBoxes")
    {
      // Invalid - set custom message and return false
      validationMessage = 
          "Use this document type only for boxes that have been marked for disposal (box# >= 999000";
      return false;
    }
    // Return the original validation value that was passed to the method
    return valid;
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
    return false;
  }
}

 

BatchDataFieldIndexing Method

This method is called from the Index module at the start of auto-index processing. It is called for each batch index field.

 

Parameters:

 

Direction Parameter Type Description
IN batch IBatch The current batch
dataRecord IDataRecord The data record containing the batch-level index fields
dataField IDataFieldValue The current data field within the batch record
Example – If batch index field BatchSource has no value, assign it the value of “DEFAULT”.
public virtual void BatchDataFieldIndexing(IBatch batch, IDataRecord dataRecord, IDataFieldValue dataField)
{
  try
  {
    if(dataRecord["BatchSource"].StringValue.Length == 0)
      dataRecord["BatchSource"].Value = "DEFAULT";
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
  }
}

 

BatchDataFieldBeforeValidation Method

This method is called prior to validation of each data field in the batch data record.

 

Parameters:

 

Direction Parameter Type Description
IN batch IBatch The current batch
dataRecord IDataRecord The data record containing the batch-level index fields
dataField IDataFieldValue The current data field within the batch record
Example – If the Processing Date is not specified, check the value of the PO Date index field. If it’s a valid date, assign it to the ProcessingDate index field. If not, assign the current date to ProcessingDate.
public virtual void BatchDataFieldIndexing(IBatch batch, IDataRecord dataRecord, IDataFieldValue dataField)
{
  try
  {
    if(dataField.Name == "ProcessingDate" &&
       string.IsNullOrEmpty(dataField.StringValue) &&
       !string.IsNullOrEmpty(dataRecord["PoDate"].StringValue))
    {
      DateTime checkDate;
      if(DateTime.TryParse(dataRecord["PoDate"].StringValue, out checkDate))
      {
        dataField.Value = checkDate;
        return;
      }
    }
    dataField.Value = DateTime.Now;
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
  }
}

 

BatchDataFieldValidated Method

The BatchDataFieldValidated method is called after index processing and normal validation of all batch index fields. It runs for each index field in the batch data record. Return true from this method if the data field passes validation, or false if it does not.

 

Parameters:

 

Direction Parameter Type Description
IN batch IBatch The current batch
dataRecord IDataRecord The data record containing the batch-level index fields
validate true/false True if the record is currently valid, false if it is not
IN/OUT validationMessage string A user-defined, custom validation message

 

Returns:

True or False

 

Example – If the Processing Date is not specified, check the value of the Scan Date index field. If it’s a valid date, assign it to the ProcessingDate index field and return true. If not, return false along with an error message.
public virtual bool BatchDataFieldValidated(IBatch batch, IDataRecord dataRecord, IDataFieldValue dataField, bool valid, ref string validationMessage)
{
  try
  {
    // If ProcessingDate has a value, just return the value
    // of the parameter "valid"
    if(dataField.Name != "ProcessingDate" ||
       !string.IsNullOrEmpty(dataField.StringValue))
      return valid;
    // If ProcessingDate has no value, try to assign the ScanDate value
    if(!string.IsNullOrEmpty(dataRecord["ScanDate"].StringValue))
    {
      DateTime checkDate;
      if(DateTime.TryParse(dataRecord["ScanDate"].StringValue, out checkDate))
      {
        dataField.Value = checkDate;
        return true;
      }
    }
    // Unable to assign the ProcessingDate value, so return false along with an error message
    validationMessage = "Please supply a value for Processing Date";
    return false;
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
    return false;
  }
}

 

For Folder Level

FolderDataRecordInitialize Method

The FolderDataRecordInitialize method is called when the folder data record is first created. It is called during Capture / Import as each folder is created, and in the QA module when the client elects to manually create a new folder. Use this method to initialize folder index fields or folder properties.

 

Parameters:

 

Direction Parameter Type Description
IN folder IFolder The current folder
dataRecord IDataRecord The data record containing the folder-level index fields

 

Example – Set the folder’s FolderNote property to identify the user and machine used to create the folder.
public virtual void FolderDataRecordInitialize(IFolder folder, IDataRecord dataRecord)
{
  try
  {
    folder.FolderNote = string.Format("Created by {0} on machine {1}",
                                      System.Security.Principal.WindowsIdentity.GetCurrent().Name,
                                      System.Environment.MachineName);
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
  }
}

 

FolderDataRecordIndexing Method

The FolderDataRecordIndexing method is called prior to running (or re-running) zone OCR and OMR for folder-level indexes. Use this method to initialize folder index fields or folder properties.

 

Parameters:

 

Direction Parameter Type Description
IN folder IFolder The current folder
dataRecord IDataRecord The data record containing the folder-level index fields

 

Example – If folder index field FolderDocSource has no value, assign it the value of “DEFAULT”.
public virtual void BatchDataRecordIndexing(IFolder folder, IDataRecord dataRecord)
{
  try
  {
    if(dataRecord["FolderDocSource "].StringValue.Length == 0)
      dataRecord["FolderDocSource "].Value = "DEFAULT";
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
  }
}

 

FolderDataRecordValidated Method

The FolderDataRecordValidated method is called after index processing and normal validation of all folder index fields. If one or more index values failed validation, the incoming “valid” parameter will be false. Use this method to return a custom error message or to programmatically correct validation issues in each of the data record’s fields. Return true from this method if the record passes validation, or false if it does not.

 

Parameters:

 

Direction Parameter Type Description
IN folder IFolder The current folder
dataRecord IDataRecord The data record containing the folder-level index fields
valid bool True if the record is currently valid, false if it is not
IN/OUT validationMessage string A user-defined, custom validation message

 

Returns:

True or False

 

Example – Verify that the value of folder index field ProcessingDate is earlier than the value of folder index field ScanDate. If not, return false and return an error message.
public virtual bool FolderDataRecordValidated(IFolder folder, IDataRecord dataRecord, bool valid, ref string validationMessage)
{
  try
  {
    if((DateTime)dataRecord["ProcessingDate"].Value >= (DateTime)dataRecord["ScanDate"].Value)
    {
      validationMessage = "Invalid Processing Date - must be earlier than the Scan Date";
      return false;
    }
    else
      return valid;
  } 	
  catch (Exception exception)
  {
    base.ProcessException(exception);
    return false;
  }
}

 

FolderDataFieldIndexing Method

This method is called for each folder index field during auto-indexing. It is also called when a user selects a folder index field for editing in the Capture / Import or Index module screens, and when the user toggles on indexing in the Index module form. The script runs before zone OCR/ICR processing, so current OCR/ICR values are not available.

 

Parameters:

 

Direction Parameter Type Description
IN folder IFolder The current folder
dataRecord IDataRecord The data record containing the folder-level index fields
dataField IDataFieldValue The current index field being processed

 

Example – If folder index field PONumber has no value, build and assign a default PO number.
public virtual void FolderDataFieldIndexing (IFolder folder, IDataRecord dataRecord, IDataFieldValue dataField)
{
  try
  {
    if(dataField.Name != "PONumber")
      return;
    if(string.IsNullOrEmpty(dataField.StringValue))
    {
      dataField.Value = dataRecord["VendorNumber"] + "-9999-" + dataRecord["Year"];
    }
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
  }
}

 

FolderDataFieldBeforeValidation Method

FolderDataFieldBeforeValidation method is called prior to validation of each data field in the folder data record. Use this method to initialize or modify index field values before validation occurs.

 

Parameters:

 

Direction Parameter Type Description
IN folder IFolder The current folder
dataRecord IDataRecord The data record containing the folder-level index fields
dataField IDataFieldValue The current index field being processed

 

Example – If folder index field PONumber has no value, build and assign a default PO number.
public virtual void FolderDataFieldBeforeValidation (IFolder folder, IDataRecord dataRecord, IDataFieldValue dataField)
{
  try
  {
    if(dataField.Name != "PONumber")
      return;
    if(string.IsNullOrEmpty(dataField.StringValue))
    {
      dataField.Value = dataRecord["VendorNumber"] + "-9999-" + dataRecord["Year"]
    }
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
  }
}

 

FolderDataFieldValidated Method

The FolderDataFieldValidated method is called after index processing and normal validation of all folder index fields. It runs for each index field in the folder data record. Return true from this method if the data field passes validation, or false if it does not. When returning false, you can also return a custom error message.

 

Parameters:

 

Direction Parameter Type Description
IN folder IFolder The current folder
dataRecord IDataRecord The data record containing the folder-level index fields
dataField IDataFieldValue The current index field being processed
valid bool True if the record is currently valid, false if it is not
IN/OUT validationMessage string A user-defined, custom validation message

 

Returns:

True or False

 

Example – Call a SQL Server Database function to validate the value in the folder index field VendorNumber.
public virtual bool FolderDataFieldValidated(IFolder folder, IDataRecord dataRecord, IDataFieldValue dataField, bool valid, ref string validationMessage)
{
  try
  {
    // Check the index name - we only want to validate VendorNumber
    if(dataField.Name != "VendorNumber")
      return valid;
    // Connect to the database
    using(SqlConnection sqlConn = new SqlConnection("<your database connection string>"))
    {
      sqlConn.Open();
      // Build the Sql Command, specifying the name of the SQL Server function (dbo.ValidateVendor)
      using(SqlCommand sqlCmnd = new SqlCommand("dbo.ValidateVendor", sqlConn))
      {
        sqlCmnd.CommandType = System.Data.CommandType.StoredProcedure;
        // Build the vendor number parameter used by dbo.ValidateVendor
        SqlParameter vendNumParam = new SqlParameter("@VendNum", System.Data.SqlDbType.VarChar);
        vendNumParam.Direction = System.Data.ParameterDirection.Input;
        vendNumParam.Value = dataField.StringValue;
        // Return the result of the call to dbo.ValidateVendor
        return (bool)sqlCmnd.ExecuteScalar();
      }
    }
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
    return false;
  }
}

 

For Document Level

DocumentDataRecordInitialize Method

The DocumentDataRecordInitialize method is called when a new record is created and added to a document, either manually or automatically. The record contains default values for each field.

 

Parameters:

 

Direction Parameter Type Description
IN document IDocument The current document
dataRecord IDataRecord The new record for the document

 

Example – Use an external database to record the user ID and the date/time when the record was added.
public virtual void DocumentDataRecordInitialize(IDocument document, IDataRecord dataRecord)
{
  try
  {
    using(SqlConnection sqlConn = new SqlConnection("<your database connection string>"))
    {
      sqlConn.Open();
      // Build the Sql Command to execute a SQL Server stored procedure, which accepts two parameters:
      // the user ID and a date/time stamp in string form
      using(SqlCommand sqlCmnd = new SqlCommand("dbo.BigBrotherIsWatching", sqlConn))
      {
        sqlCmnd.CommandType = System.Data.CommandType.StoredProcedure;
        SqlParameter userID = new SqlParameter("@UserID", System.Data.SqlDbType.VarChar);
        SqlParameter dateTimeStamp = new SqlParameter("@TimeStamp", System.Data.SqlDbType.VarChar);
        // Add the user ID parameter
        userID.Direction = System.Data.ParameterDirection.Input;
        userID.Value = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
        // Add the timestamp parameter
        dateTimeStamp.Direction = System.Data.ParameterDirection.Input;
        dateTimeStamp.Value = DateTime.Now("MM-dd-yyyy HH:mm:ss");
        // Execute the stored procedure
        sqlCmnd.ExecuteNonQuery();
      }
    }
  }
  catch (Exception exception)
  {
    base.ProcessException(exception);
  }
}

 

DocumentDataRecordIndexing Method

The Index module (and the Capture/Import module, if the index option is selected) calls the DocumentDataRecordIndexing method when changing from one document to another (either manually or during auto-indexing), or when the user enables indexing through the menu bar toggle button. DocumentDataRecordIndexing is called before zone OCR runs. It is called for each record in the document.

 

Parameters:

 

Direction Parameter Type Description
IN document IDocument The current document
dataRecord IDataRecord The current record for the document

 

DocumentDataRecordValidated Method

The DocumentDataRecordValidated method runs after document index processing and normal record validation, just prior to changing from one document to another during indexing. Return true from this method if the record passes validation, or false if it does not. When returning false, you can also return a custom error message.

 

Parameters:

 

Direction Parameter Type

Description

IN   document IDocument The current document
dataRecord IDataRecord The current record for the document
valid bool True if the record is currently valid, false if it is not
IN/OUT validationMessage string A user-defined, custom validation message

 

Returns:

True or False

 

DocumentDataFieldIndexing Method

This method is called for each document index field during auto-indexing. It is also called when a user selects a document index field for editing in the Capture / Import or Index module screens, and when the user toggles on indexing in the Index module form. The script runs before zone OCR/ICR processing, so current OCR/ICR values are not available.

 

Parameters:

 

Direction Parameter Type Description
IN document IDocument The current document
dataRecord IDataRecord The current record for the document
dataField IDataFieldValue The current index field being processed

 

DocumentDataFieldBeforeValidation Method

DocumentDataFieldBeforeValidation method is called prior to validation of each data field in the document data record. Use this method to initialize or modify index field values before validation occurs.

 

Parameters:

 

Direction Parameter Type Description
IN document IDocument The current document
dataRecord IDataRecord The current record for the document
dataField IDataFieldValue The current index field being processed

 

DocumentDataFieldValidated Method

The DocumentDataFieldValidated method is called after index processing and normal validation of all document index fields. It runs for each index field in the document data record. Return true from this method if the data field passes validation, or false if it does not. When returning false, you can also return a custom error message.

 

Parameters:

 

Direction Parameter Type Description
IN document IDocument The current document
dataRecord IDataRecord The current record for the document
dataField IDataFieldValue The current index field being processed
valid bool True if the record is currently valid, false if it is not
IN/OUT validationMessage string A user-defined, custom validation message

 

Returns:

True or False

 


Miscellaneous

BeforeLookupsProcessed Method

The BeforeLookupsProcessed method is called before any Query lookup is run from the Capture, Index or Quality Assurance modules.

 

Parameters:

 

Direction Parameter Type

Description

IN batch IBatch The current batch
folder IFolder The current folder
document IDocument The current document
documentRecord IDocumentRecord The current record for the document

 

AfterLookupsProcessed Method

The AfterLookupsProcessed method is called after any Query lookup is run from the Capture, Index or Quality Assurance modules.

 

Parameters:

 

Direction Parameter Type

Description

IN batch IBatch The current batch
folder IFolder The current folder
document IDocument The current document
documentRecord IDocumentRecord The current record for the document

 

AfterBatchLoaded Method

The AfterBatchLoaded method is called when a batch is loaded into the Index module.

 

Direction Parameter Type Description
IN batch IBatch The batch being loaded
Was this article helpful?
0 out of 2 found this helpful

Comments

0 comments

Please sign in to leave a comment.