Hello Lada,
Let me provide you with some helfpul information.
Firstly, TDM has two types of scripts.
A. Script that you create via Tools menu | Scripting Window. Here you can write or modify simple scripts and execute them via the toolbar available in the Scripting Window. Method main() is always executed.The disadvantage of the Scripting Windows is that it is impossible to save the script inside (workaround - copy and past).
B. Script that you create via Script or Package Explorer. These scripts are usually executed in certain context (e.g. method of an object, Get or Set method of property, Event forms etc.)
-> This is the introduction. Before you start, you should consider which script you want to use.
Now, if we understand well, you want to execute a method that will perform a one-shot action with triggers. For this purpose, both types of scripts can be used. We will try to show them, please see the examples below.
A. Execute Script in Scripting Window
There is one problem here - keyword Instance etc. is not valid here. So, firstly, it is necessary to “put” a model to the script. There are two possible ways how to do it:
a) Via option Show Registered Objects
- Open Scripting Window.
- From the main menu, select View | Show Registered Objects. -> A new windows will appear (see the attached screenshot).
- In the Available Objects box, select the model and click the arrow to add it to the Selected Objects box.
- In the Name in Script column or via F2, you can modify the model name the way you call the model from your script.
b) Via the System object this way:
var Application = System.GetInterface(‘Application’);
var Model = Application.Models.GetObjectByName(‘MyModel’);//By name
or
var Application = System.GetInterface(‘Application’);
var Model = Application.Models.GetObject(0);//The parameter in GetObject determines with which model the script should work. 0 is the first model listed in the Application View. 1 is the second model listed in the Application View etc.
Tip! - See the Reference Guide, object List.
B. Execute Script from a Form
Here is a brief list of steps to do. Daril created a sample package for you that demonstrates it and where these instructions are also written - see the Properties of the attached package | Description tab.
If you like to check out the attached package, please copy it to your user packages (where My Package and other add-ons are stored). Default path is:
C:\Documents and Settings\user name\My Documents\Toad Data Modeler\Packages{DCB5CB9B-CF65-4350-86B5-285D246FC5AC}
Note: Open TDM then. If it was opened, remember to restart it. Open MS SQL 2005 model, add entity and click the Triggers tab - see the new button Actualize Triggers.
==============
Steps to do to execute script from a form in a model:
A: Create an add-on package first.
File | New Package | enter a package name and select a Package Extension - a package that you like to extend. Usually, it should be Database XXX where XXX is the name of a database platform. You can also extend more databases at one jump.
B: Create a button on a form.
- In Options | Expert Mode | the checkbox Save the definitions to the “My Package” checkbox must be clear. - To be able to save modifications to other packages than My Package.
- Open the form where you like to add the button.
- Right-click the form and select Customize Form As.
- From the Package List, select the add-on package.
- Add a button for which you define a name and caption.
- Click the x button on the form to close the edit mode and select Save Form To…
- Save the add-on package (via Package Explorer).
- Restart TDM.
C: Create a new script.
- Open Package Explorer and find the add-on package.
- Right-click the Scripts folder and select Add Script.
- Create a new script of the same name as the form has, e.g. FmPEREntityEdit.
- In the script, create a new function of a name that will consists of the button name and event name, e.g. MyButtonOnClick. This function is without any parameter.
- Write code of this function and confirm Commit.
- Save the package.
If you have any questions, please write us back. Thanks.
Regards,
Vladka + Daril
Message was edited by: vladka