This sample shows you how to iterate entities and attributes and how to recognize PK, PFK or FK attributes.
function main()
{
var app = System.GetInterface('Application');
var Model = app.Models.GetObject(0); // gets first model in application
var e, a, iterEntity, iterAttribute;
Model.Lock();
for (e=0; e<Model.Entities.Count; e++) // iterate entities
{
iterEntity = Model.Entities.GetObject(e);
iterEntity.Lock();
for (a=0; a<iterEntity.Attributes.Count; a++) // iterate attributes
{
iterAttribute = iterEntity.Attributes.GetObject(a);
if(iterAttribute.IsPrimaryKey == 1) // check if attribute is PK
{
if(iterAttribute.FKForeignKeys.Count !=0)
Log.Information(iterEntity.Name+'-'+iterAttribute.Name+'-PFK');
else
Log.Information(iterEntity.Name+'-'+iterAttribute.Name+'-PK');
}
else
{
if(iterAttribute.FKForeignKeys.Count !=0)
Log.Information(iterEntity.Name+'-'+iterAttribute.Name+'-FK');
}
}
iterEntity.UnLock();
}
Model.UnLock();
Model.RefreshModel();
}
Edit the Model Properties form. See the "Modify Form" topic to find out how to edit existing form.
Add there a new button and remember the name of the form - FmPERModelEdit. The name can be found in the Form Explorer.
Defined caption for the button - Write Customer Feedback To Log.
Set the name of the button to FeedbackButton.
Create a new script with the name of the Model Properties form - FmPERModelEdit.
Write event function to the script.
function FeedbackButtonOnClick()
{
WriteFeedbackToLog.WriteFeedback()
}
When you click the button, an output will be displayed in Message Explorer (Log).
For more information, see Modify HTML Reports.
To modify HTML reports, we need to extend existing method. The first thing we need to do is to find out what script should be extended.
In Script Explorer, you can see BasicHTMLPERReportOR script with function ReportTableUserProperties. This is the script that generates Tables pages in HTML reports, specifically the section Table Properties.
You can also see script BasicHTMLPERReportOR10 that extends the BasicHTMLPERReportOR script.
Now we now need to write a script that will extend the ReportTableUserProperties function defined in the BasicHTMLPERReportOR script.
For that purpose, we need to open our CustomerFeedback metamodel and the method there.
Open the CustomerFeedback metamodel, add there a new class (see the Class icon in the toolbar), edit the class and set the name to BasicHTMLPERReportOR10. (One extension of that class already exists, in our metamodel we will create another extension of the class).
Define Object Type (the value can be currently found out in metamodel to HTML report for Oracle 10g package).
Add the ReportTableUserProperties method to the class.
Add two new parameters to the method. (The method name and number of parameters must be identical to the original method - see the first screenshot).
Return back to the General tab. Click Reload. Script name and method name will appear there. Add a prefix My to it (this will be changed in future, no manual modification will be required).
Click Edit Script.
Click OK and define code for the ReportTableUserProperties method that extends the existing method of the same name.
function ReportTableUserProperties(Document, Entity)
{
// Table definition
Table = Document.CreateTable(false,true);
Table.CreateColumn(20);
Table.CreateColumn(80);
var row = -1;
if (Entity.ConfirmedByCustomer == true)
{
Table.CreateCell( ++row,0,'Confirmed' );
Table.CreateCell( row,1,'Yes' );
}
else if (Entity.ConfirmedByCustomer == false)
{
Table.CreateCell( ++row,0,'Confirmed' );
Table.CreateCell( row,1,'No' );
}
else
{
Table.CreateCell( ++row,0,'Confirmed' );
Table.CreateCell( row,1,'Undefined' );
}
if (Entity.NotesFromCustomer.length > 0)
{
Table.CreateCell( ++row,0,'Notes from Customer' );
Table.CreateCell( row,1, Entity.NotesFromCustomer );
}
if (row > -1)
{
Document.WriteStyled( 'CAPTION2', 'Customer Feedback' );
Table.Draw();
Table.Close();
}
Instance.ReportTableUserProperties(Document, Entity);
};
Table.CreateColumn(20) - the CreateColumn function belongs to the HTMLReportTable class. All functions related to the Table object can be found in the Toad Data Modeler Reference.
Entity.ConfirmedByCustomer - represents the variable we added earlier to the CustomerFeedback metamodel.
Entity.NotesFromCustomer.length - standard JavaScript function that returns number of characters of the NotesFromCustomer string.
Document.WriteStyled - represents function that belongs to the HTMLDocument class.
Instance.ReportTableUserProperties(Document, Entity);
When you generate HTML reports now, you will see the following output. New section Customer Feedback is generated on top, followed by the Table Properties part, as originally defined in the ReportTableUserProperties function in script BasicHTMLPERReportOR.
Toad Data Modeler allows you to edit some forms and frames for more comfortable work.
It is a form of which appearance you can edit to meet your needs and requirements. You can add, change components and delete user components (those you created).
Right-click the form to see the pop-up menu. If there's the Customize Form (as) option, the form is editable.
Example: The Entity Properties form
Properties of editable frames are similar to properties of editable forms, however frame represents only a part of a form, not complete form. E.g. the Options form has editable frames Application, Graphics etc.
To customize appearance and functionality of forms to suit your needs, e.g. you want to have different options for different database types.
If you model your own property in metamodel, you will probably want to visualize it somehow (write out its value to edit etc.) Therefore it's necessary to edit appropriate form and insert to it a new component to which you will assign appropriate property then. Also, to inserted components, you can add values by scripting.
To edit a form
Right-click the form and select Customize Form or CustomizeForm as.
Customize Form |
The changes will be saved to your user package My Package. |
Customize Form as |
The changes will be saved to another package than My Package. This option is disabled by default. To enable it, select Settings | Options | Expert Mode and uncheck the Save the definitions to the My Package checkbox. |
Forms can be edited via the following tools :
Forms of these three tools can be docked in Toad Data Modeler environment at your convenience.
If you want to hide/show any of these tools permanently, you can clear/select appropriate option in:
Example: The Entity Properties form that is being edited now.
To finish editing a form
Close the form that you have just edited (click x in the right-hand corner, e.g. in the Entity Properties form).
After you close the edited form, you need to save the changes to package.
|
Note: You will not finish editing the form by closing any of the tool forms (Inspector, Explorer or Palette Component). If you close any of them, the Show option for the tool (Show Inspector, Show Explorer...) will be automatically cleared. If you edit a form next time, the form of this tool will not display. To display it again, you need to enable the Show option either in the Designer Mode Options or in the Settings menu | Options | Editable Forms. |
To save the changes
The changes will be saved to appropriate packages, however to preserve them even after you close the application, you have to save also the packages.
Changes will be saved either to actual package, or user package (according to the settings in the Settings menu | Options | Paths).
If you want to save the changes to another package, you have to start the edit process with option Edit Form as, then select the package and finally click Save Form to to save the changes.
Right-click the form to see the following options:
Option | Description |
---|---|
Customize Form |
Edits a form. All changes will be stored to My Package user package (file My Package.txg). |
Edits a form in a state according to the selected package. (Only the components that are saved in the selected package and its child packages will be available.) This option is available only if checkbox Save the Definitions to the 'My Package' is clear. - See the checkbox in the Settings menu | Options | Expert Mode. | |
Load Form |
Reloads a form. |
Save Form |
Saves changes in the default package (see the Settings menu). |
Save Form to |
Saves changes to previously selected package (see Edit Form as). |
Designer Mode Options |
Here, you can hide/show the tools for next form edit. |
Default Values of Object |
Opens the dialog where you can define or edit default values of appropriate form/dialog/frame. |
© 2023 Quest Software Inc. ALL RIGHTS RESERVED. Feedback Terms of Use Privacy