Creating a Script Library

Often enough you create some code that you will need to re-use in different places. The event handling and actions provide the ability to re-use code in some cases, but in other cases you need more flexibility in when you can invoke that code. In this case you should use the script library feature.

In the Application / Plugins area you can create any number of DbfScript libraries. These libraries are collections of functions. The functions can be invoked from anywhere in the application, including from reports.

To create a script library, go to the Plugin section under the Application and select a Module Type of 'DbfScript Library', and give the library a name.

Create that record. Then drill down to Script Engine Functions. You can create an entry in the Script Engine Functions for each function you wish to add. You simply give it a name (which should be an identifier, without any spaces and starting with a letter), and enter the DbfScript below that.

In your script, you can access the fields of the parameters record as #input, and the passed-in path as &path. You can then use the "return" keyword to return a record or text at the end of the function.

Once create you can then invoke your library function using the RunPlugin function, for example:

var #ret = RunPlugin("MyLibrary:MyFunction", &path, record ( Arg1="arg1", Arg2="arg2" ))

In this case, the DbfScript library is called MyLibrary, and the function was called MyFunction. We're passing in a new record with two fields, Arg1 and Arg2. These would be accessed within the library script as #input/Arg1 and #input/Arg2.

Script History

One benefit of using script libraries is that any changes you make to a script will be stored with a history of changes, making it easy to revert back to an older script should there be any problems. You can access this under the History drilldown under the script, after you make changes to it. There are also links on each change to show the diffs from the previous version.


Next Topic:
v4.2.0.956 (beta)
Up Since 2/29/2024 12:02:23 AM