|
<< Click to Display Table of Contents >> Navigation: Custom commands > Custom scripts on the client |
Custom scripts on the client
Web Client added the ability to execute custom scripts on the client. This feature is a complement to the ability to run server side scripts.
The script is triggered by a click on a custom menu entry displayed in the contextual menu of a document, as for server side scripts.
The declaration of the command must be added to the file \Program Files\DBWORKS Stand Alone\WebViewer\Scripts\customMenus.xml and is very similar to the declaration used for server side scripts:
![]()
Add a tag command and define an attribute id that must be unique inside the file, in the example above it's 'commandID'.
The attribute english and italian indicate the caption that the menu command has on the client, depending on the current language in use.
Finally, the most important attribute is clientScript and indicates a script that must be available in the directory \Program Files\DBWORKS Stand Alone\WebViewer\Scripts. In this specific case the script name is \Program Files\DBWORKS Stand Alone\WebViewer\Scripts\myScript.vbs .
Inside the tag, the visibilityCondition determines when the command is available. Here again you can set conditions based upon the record field values, and this is the case, or set access limitations based upon the personality or group of the user. Please refer to the general topic for custom menus for more information on how to apply restrictions to custom commands.
The client downloads the script from the server and runs it. The script contains implicitly two objects that you needn't declare:
oRsdoc is a COM object of type ADODB.Recordset that contains the fields and values of the DOCUMENT table for the document that was right clicked
oScriptResult is an object defined and documented for server Side scripting to which a new method was added:
openURL(<url>)
where <url> is a string with a URL to be opened on the client. Note that the choice of the browser is generally left to the current settings in the client OS, and the operation is the equivalent of a double click on a Windows shortcut pointing to the URL.
oDOWNLOAD_DIRECTORY is a variable containing the local Download Directory, if already assigned.
An example of a valid script:

The above script, for the sake of brevity and simplicity, does only two things: it displays in a message box the value of the field ID of the record clicked and opens the web browser on the index page of MechWorks' web site .
You can run a script on a selection of documents. In this case the recordset rsDoc is an ADO Recordset containing several records.
You can create files that can be eventually uploaded to the server.
You should first define the directory where the files should be uploaded: in the file ...\DBWorks\WebViewer\WebViewerOptions.txt define the upload directory as follows
custom_upload_directory "c:\temp\uploads"
where the directory path - in this case c:\temp\uploads - is referred to the file system on the web server.
Inside the script the object scriptResult exposes two functions to upload files
oscriptResult.UploadFile <filePath>
oscriptResult.UploadAndDelete <filePath>
where <filePath> is the full path to the file to be uploaded to the server.
The function UploadAndDelete deletes the file after uploading it to the server.
If the upload fails an error is raised by the object and should be handled in the calling script.
The file is only uploaded and is not processed server side.
This is a task that you can safely perform in you script creating an instance of the object FileSystemObject, but the object scriptresult offers a handy shortcut creating the file for you in the tem porary folder.
scriptResult.saveToTextFile <filename>, <content>
where <filename> is the simple file name, not a full path and <content> is the text to be saved into the file. The function returns the full path to the newly created file.