Script Editor

Quick Fields contains a powerful Script Editor that enables you to write VB.NET and C# scripts. The editor is color-coded, includes an auto-completion feature, and enables you to check for syntax errors.

Script Editor Interface

The Quick Fields Script Editor interface is comprised of three panes:

Project Explorer pane

The Project Explorer Pane contains folders, most of which represent a different event that takes place during a session, such as Page created or Document stored. Scripts are associated with events, which control when they will be executed.

To enable or disable a script

  • Right-click the script in the Project Explorer pane and select or clear Enabled. Disabled scripts will not run with the session.

This pane also contains a folder named References that stores all of the namespaces that are available to your script.

To add a reference

  • Right-click on the folder and select Add Reference.

Script pane

In most cases, this pane appears in the center of the screen and will contain one or more tabs, each of which represents a different script that is currently open.

To open a script that you've created

  • Expand its parent folder in the Project Explorer pane and double-click the script.

At the top of each script, there are two type/member drop-down lists, each of which enables you to jump to specific areas of your script. In most cases, the left box jumps to classes and the right box jumps to methods. You can access additional options by right-clicking in the Script pane, by using the toolbar buttons, or by selecting Edit from the menu bar (some of these options are covered in the Advanced Script Editor Options section).

Error List pane

After creating your script, you can check it for syntax errors.

To check for errors

  • Select the Build option in the menu bar or toolbar or press F6.

If errors are found, they will be displayed in this pane. Keep in mind that building your script does not actually run it. To run your script, run a sample session with the script enabled.

Scripting Events

Quick Fields contains a powerful Script Editor that enables you to write VB.NET and C# scripts. In order for a script to run, it must be associated with an event that takes place during a session. When the event occurs, it calls a built-in method that executes your script (assuming you have placed your script inside the method). There are a number of events to choose from.

Event Name Method Name Description
After document processed OnAfterDocumentProcessed Occurs when the last page of a document is scanned and has been processed, before the document is added to the user interface or is sent immediately.
After page processed OnAfterPageProcessed Occurs when a page is finished being processed by a document class. Does not apply to unidentified pages.
Before document stored OnBeforeDocumentStored Occurs directly before a document is stored in the repository.
Before page identified OnBeforePageIdentified Occurs after Pre-Classification Processing and directly before the page begins the First Page Identification process.
Document created OnDocumentCreated Occurs when a document is created by a scan source. For example, when a session captures an electronic document (e.g., a PDF file) or when Laserfiche Capture Engine or Universal Capture create a document using the Keep each entry as a separate document option.
Document identified OnDocumentIdentified Occurs after a document is identified but before its first page is processed.
Document stored OnDocumentStored Occurs directly after a document is stored in the repository. When the method is called, the document already exists in the repository, which enables you to use Laserfiche Server Objects in your script to interact with the newly created document.
Document unidentified OnDocumentUnidentified Occurs when a document is unidentified and allows for reassigning the document to another document class.
Page created OnPageCreated Occurs at the start of processing when a page is scanned by a scan source.

Creating a Script

Quick Fields contains a powerful Script Editor that enables you to write VB.NET and C# scripts. Follow the steps below to create a new script.

Tip: It is important to consider the impact a script could have on the performance of your session. For events associated with documents, the script will run once for each document. For events associated with pages, the script will run once for each page. For example, if you called the e.API.ShowMessageBox method inside the OnPageCreated method, and then scanned a 200 page document, the message box would appear 200 times.

Note: For the most part, Quick Fields does not interact with a Laserfiche repository until documents are stored. As a result, if your script needs to connect to your Laserfiche repository, you must provide the connection yourself using standard Laserfiche Toolkit code. For more information on Laserfiche Server Objects, see the Laserfiche Toolkit documentation.

To create a script

  1. Within an open Quick Fields session, select Script Editor under Tools in the menu bar.
  2. You may be prompted to choose a programming language: Visual Basic (VB.NET) or C#. Choose one.

    Tip: You can also control this setting by selecting Tools, Options, Current Session, General and configuring Scripting Options. The language setting is tied to the session that is currently open, not to Quick Fields in general.

  3. Right-click one of the event folders in the Project Explorer pane, point to Add, and select Quick Fields Script.
  4. In the Select a Scripting Event dialog box, select the appropriate event for your script. In most cases, the name of the event you select will match the name of folder you right-clicked in the previous step. Select OK.

    Note: When you create a script, it is assigned to, and only available within, the active session. For example, the scripts you create in Session 1 will not available to Session 2.

  5. A new tab will appear in the Script pane, inside of which will be some code that will include:

    • Import/Using statements: A series of imports that are required to run your script.

      Tip: If your script requires additional imports, you can include them here. You must also add a reference to any namespaces that are not in your References folder. To do so, right click on the References folder in the Project Explorer pane and select Add Reference. In the Add References dialog box, choose a reference from the list or click the Browse button to locate a file.

    • Namespace: The QuickFields.Scripting namespace.
    • Class: A class named ScriptX, where X will be a different integer depending on the number of scripts associated with the session.
    • Method: The name of the method depends on the event you selected. Place your script inside of this method.
    • XML Comments: Used to explain the default blocks of code.

Sample Script

Quick Fields contains a powerful Script Editor that enables you to write VB.NET and C# scripts. In the sample script below, a message box is displayed to the user after a page is processed. The code in red represents the custom script.

The method associated with the script's event (OnAfterPageProcessed) accepts a single parameter that is defined for you: e. You can use e to access most of the methods, properties, interfaces, etc. that you will need to interact with the page, document, and session. The options available to you within a script depend on the event you have selected. For example, you cannot access the name of a document class in an event that occurs before the document in question is identified. As another example, you could not use Laserfiche Server Objects to interact with the active document until after it is stored in the repository (until the OnDocumentStored method is called). In addition, the available options also vary depending on whether the event you have selected is associated with a page (e.g., OnPageCreated) or a document (e.g., OnDocumentCreated).

Show me the script in VB.NET.

Imports System
Imports System.ComponentModel
Imports Laserfiche.QuickFields.Scripting
Imports Laserfiche.QuickFields.Scripting.Events

Namespace QuickFields.Scripting
'''<summary>
'''Provides one or more methods that can be executed when a Quick Fields event occurs.
'''</summary>

Partial Public Class Script1
' The ShowMessageBox, ShowErrorBox, ShowDialog, and WriteMessage functions, accessible
' through the e.API property, are available to help debug your scripts.

'''<summary>
'''This method executes when the After page processed (Page.Processed.After) event occurs.
'''</summary>
'''<param name="e">Contains data about the page processed event.</param>
<ScriptEvent("Page.Processed.After")> _
Public Sub OnAfterPageProcessed(ByVal e As AfterPageProcessedArgs)

e.API.ShowMessageBox("Hello world!")

End Sub
End Class
End Namespace

ClosedShow me the script in C#.

Advanced Script Editor Options

When you are creating your script, the following advanced features may be useful.

Generate Entry Point

You can call any of the events from any script, regardless of which event folder a script is in.This feature allows you to combine a series of scripts into one.

Note: Do not insert a method inside another method, as doing so will prevent your script from working.

To generate an entry point

  1. Right-click where you want the method inserted and select Generate Entry Point.
  2. In the Select a Scripting Event dialog box, select a method and click OK.

Bookmarks

You can assign bookmarks to specific lines of code, which enables you to quickly jump to them.

To assign a bookmark

  • Right-click on the line of code you want to bookmark and select Toggle Bookmark.

To navigate from one bookmark to another

  • Select the (Previous Bookmark and Next Bookmark) buttons on the toolbar.

To remove a bookmark

  • Right-click on the line of code and select Toggle Bookmark again.

Intelliprompt

This feature allows you to manually control the information that is displayed next in the Intelliprompt drop-down list.

To access the Intelliprompt actions

  • Point to Intelliprompt under Edit in the menu bar.

Script Editor Options

You can set options for the Script Editor itself.

To control general usability options in the Script Editor

  • Select Options from the Tools menu.

To control display options

  1. Select View from the menu.
  2. Select or clear the items to display.

For more detailed information on Quick Fields scripting, such as sample scenarios and detailed code samples, see the white paper on Extending Quick Fields Scripting.