you're reading...
PowerDesigner, XEM

Recursion and Extended Attributes

Another quick one today.  I’ve got some large models which are divided into packages.  I’m automating some tasks with scripts which I can configure using extended attributes (see earlier posts).

Let’s say I have a parameter for a script called “Audit” which can be true or false.  My model is divided into 3 packages, each containing a set of tables.  I want to set the default for the model to be True and have the script behave appropriately if I don’t do anything else.  I’d also like to be able to override it for a package and have the script work appropriately.  And since packages can be nested (although I haven’t seen it done much), the script needs to handle that as well.  Easy enough with a little recursion.  Create the same named extended attribute at each level (Model and Package) and use a global script to resolve it.

Here’s the script:

function getExtendedAttr(startObj, attrName)
  dim par
  dim attrVal

  set par = startObj.Parent

  if par is nothing then
     output "Error in getExtendedAttr"
     attrVal = par.getExtendedAttributeText(attrName)

     if attrVal = "" then
        if par = activeModel then
           getExtendedAttr = ""
           getExtendedAttr = getExtendedAttr(par, attrName)
        end if

        getExtendedAttr = attrVal
     end if
  end if


Now, instead of using


I use

getExtendedAttr(obj, "Audit")




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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: