External script variables
You can define and modify script variables that you can reference from script. Since script variables are stored in an external XML file, you can modify their value by editing the file. The XML file is located in the root of the project directory and is called as follows: <Project Name>_ScriptVariables.xml.
You can add or delete variables and change their values within the Project Builder using the Script Variables window. Alternatively, you can edit the XML file directly without needing to change the project.
Here is a sample XML file for the defined script variables ScriptLogPath and EnableLogging:
<?xml version="1.0" encoding="UTF-8"?> <KTM> <ScriptVariables> <ScriptVariable key="ScriptLogPath" value="C:\Logs"/> <ScriptVariable key="EnableLogging" value="TRUE"/> </ScriptVariables> </KTM>
For example, you can call the function during processing to log script errors.
Using Scripts
An organization that processes invoices receives a project from a project administrator who has configured complex scripting to optimize the document recognition rate. Several parameters, such as confidence thresholds, are stored in script variables.
The organization customizes the project to their particular workflow, changing the business rules, number and date formats, and taxes. The project administrator, working in a different location, continues to optimize the recognition rate and needs to alter the confidence thresholds. Rather than providing a new project that would overwrite any local modifications for the organization, the project administrator issues a new XML file.
Alternatively, the project administrator may own the project, making the most useful parameters via script variables available. The organization can be trained to edit the XML for efficient testing in production, and does not require more in-depth Project Builder training.
Using Script Variables to Write a User-Specific Log File
The following code sample shows how to use the defined script variables EnableLogging and ScriptLogPath in a script function. The first variable defines whether logging is enabled, and the second one defines the path for a user-specific log file.
Private Sub LogToFile(sNewLogEntry As String) If Project.ScriptVariables("EnableLogging") = "FALSE" Then no logging Exit Sub End If Dim FSO As New FileSystemObject Dim ts As TextStream Set ts = FSO.OpenTextFile(Project.ScriptVariables("ScriptLogPath") + "\log.txt" , ForAppending) ts.WriteLine(sNewLogEntry) ts.Close End Sub
Related topics: