Accessing Model properties in after script

I want to have the DDL script created enter a record into a table so we know what version the database is. Is is possible to access the value of Model Properties.version in the After Script?

Thanks in advance

Hello there,

Before we dig deep into the topic, let me ask you a few questions:

Are you planning you use Model After Script, or the particular Entity After Script for executing the INSERT statement? And by version you mean the Version property that is shown in Model Properties dialog?

One way or another, by default you cannot access the Model Version property in After Script. There is a way to do that using customization, but I would like to know the specifics of your situation first.

Regards,

Lukas

Hi, thanks for the reply

yes, I want to use the Model After script to generate an insert statement containing the version of the model property.

Alright, as I stated before, this requires some customization. Try doing the following:

  1. Enable the Expert Mode in TDM (Settings Menu | Options | General | Expert Mode

  1. Open the Package Explorer (Expert Mode Menu | Customization | Package Explorer)

CustomProperty2.png

  1. Your Package Explorer most likely looks like this. First hide the system Packages (red), you won't need them anyway.

2376.CustomProperty3.png

  1. Now create your own new Package.

CustomProperty4.png

  1. A dialog pops up where you configure the Package settings. Give your Package a name in the General tab and in the Package Extension tab move the Physical Entity Relationship Model Package to Selected. Confirm.

CustomProperty5.png

  1. Right-click your created Package and select Open Metamodel.

CustomProperty6.png

  1. The Package Metamodel is opened. Right-click anywhere on the Workspace and select Add Class.

CustomProperty7.png

  1. There will be a Class named PERModelDatabaseShortcut**. Check it and confirm by clicking OK.

CustomProperty8.png

  1. The selected Class appears on the Workspace. Open its Properties (double-click it) and change its name to "PERModel".

  1. Switch to the Properties tab, Add a new Property.

  1. Edit the Property. Enter a Name and Caption, change the Data Type to WideString, check the External checkbox and also the Read-only checkbox. Click the button next to the Get Script Method textbox. Apply the changes.

  1. Click the Edit Script button. Confirm the dialog by clicking OK. You are now editing a newly created script linked to the new Property you have created. Edit the script so it looks like on the screenshot below and then save the changes by clicking the Save button in the Scripting Window.

  1. Restart TDM and save all changes you made to your Package Metamodel. Open Model Properties. Make sure your Version property in the General tab is not empty and then switch to the After Script tab. Write in your custom Property Name in this format: <%PropertyName%>. Since my custom Property is named ModelVersion, I put in **<%ModelVersion%>. **Confirm.

  1. Now try to generate the DDL script. Before you generate the code itself, make sure to check Model After Script for generation.

  1. Check the generated SQL code. If everything went well, your Model Version number will be shown in it.

CustomProperty15.png

What you have basically done is that you have created your own custom Application Variable. You should be now able to write your INSERT statement using this Variable.

Regards,

Lukas

Super thanks! I’ll try this out!

I’m missing something, When I go through all these steps and try to generate the DDL script, it returns the message below


Error


Source: Microsoft JScript runtime error

Script: PERModel

Description: ‘Model’ is undefined

Row: 3

Column: 2

Callstack:

“FmPERGenerator” from package “Physical Entity Relationship Model”

“PERCodeGeneratorExt” from package “Generations for PER Model”

“PERModel” from package “Model Version Property”


OK


Any ideas what this might be? I’ve run through the steps a few times.

Oh, I'm sorry, it's supposed to be "return ModelTitle.Version;" in the script. I got this error as well and while I fixed it in my script I forgot to change it in the screenshot.

Amazing! Thanks a lot, this works perfectly

Thanks for the detailed demo, I never had a clue I could do anything like this inside TDM.

On Wed, Nov 26, 2014 at 10:18 AM, Lukas Knapek bounce-LukasKnapek@toadworld.com wrote:

RE: Accessing Model properties in after script

Reply by Lukas Knapek
Oh, I'm sorry, it's supposed to be "return ModelTitle.Version" in the script. I got this error as well and while I fixed it in my script I forgot to change it in the screenshot.

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or Unsubscribe from Toad Data Modeler - General notifications altogether.

Toad Data Modeler - Discussion Forum

Flag this post as spam/abuse.