//
you're reading...
PowerDesigner, XDB, XEM

Scripting Parameters

Now that the holidays are over, time to get some work done again.

I’ve been rewriting some older scripts recently (again), and a lot of them are prompting the modelers for values to be used in the scripts.  I used to do this with a dialog box but now that PowerDesigner has forms, I’ve moved almost exclusively to extended attributes and forms.  This gives me a lot more control over the form, and allows me to gather multiple parameters at the same time.  It gives me greater control over lists of values, and it allows a script to “remember” the values chosen last time the script was run.

Let’s say I want to control access to the tables in my model through views.   Within a model, there are three parameters I want to control for my view generation:

  1. Who owns the view
  2. Do I use a view suffix (and what is it)
  3. Do I want them placed on the diagram after they’ve been created

I could prompt the user three times, but that’s not terribly user friendly.  I’m also very likely to regenerate or add new views over time, and I’ll likely want the same settings each time.

So, instead of prompting for each option individually, I’m going to create an extended attribute for each and a popup form that the user can use to set the values.

Creating the Extended Attributes

First, we create the three extended attributes we’ll use to control our script. Notice that I’ve created a category to keep them organized.  I’ll create the same category for forms, templates etc. so it’s easy to see what’s related.

I’ve created “Place Access View On Diagram” as a boolean, and “Access View Suffix” as a string.  “Access View Owner” needs to be a user defined in the model, so I’ve created it as a text attribute with a list of values.  You can do this by clicking on the “Create” button next to the List of values: box on the attribute.  When the template definition box pops up, enter this code in the editor:

.foreach_item (Model.Users)
%Name%
.next (\n)

This creates a new template called “access View Owner List”.  I recommend you immediately go in, create your category, and then move the template into it for organizational purposes.

Adding the Form

Now that we have our attributes, we need a way to set them (duh).  So let’s make a form.  Create our category, create our blank form, set it as a dialog box, and use the “Add Attribute” button to add our new extended attributes.  Our extended model definition now looks like this:

Setting Parameters

Now we’ve got our extended attributes, and our form.  We need a script with a few extra lines.  Since the point of this post is parameters, not views, I’ve condensed everything but the dialog down to  a couple of dots.

So here’s our script:

Dim dlg

Set dlg = obj.CreateCustomDialog(“Access Control Views”)
If not dlg is Nothing Then
dlg.ShowDialog()
End If

And here’s the result:

Now that we’ve set the values, we need to get them for the script:

owner = obj.getExtendedAttributeText(“Access View Owner”)

suffix = obj.getExtendedAttributeText(“Access View Suffix”)

display = obj.getExtendedAttributeText(“Place Access View on Diagram”)

Done.  Now the user only has to set the values the first time the execute the script or if they change the values and you can see what values were chosen by looking at the extended attributes.

Next time, we’ll expand on this a bit with some additional options to make this more flexible.

Advertisements

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Advertisements
%d bloggers like this: