Toad World® Forums

Starting points for learning how to script a customized report


#1

Similar as I can generate a DDL script or HTML report out of box, I’d like to have a script that generates a indiviual XML representation for all tables and columns of my model.

I’d need to iterate over each table and each column, having access to table/column name and datatype.

Would you use the report or the scriptng engine?

Where are good starting points to learn how to write such a script?
Where can I find example scripts that cover similar issues?

Thanx a lot.
Andreas


#2

Hi,

you can use internal scripting or you can take advantage of the XSL tranformation. The second option might be better. Have a look at the User Guide (Help | User Guide), section Physical Modeling -> Documentation -> XSL Transformation.

I published two articles about XSL transformation. You can find them at:
http://blogs.inside.quest.com/modeling/2009/02/09/xslt-reports-part-1/
http://blogs.inside.quest.com/modeling/2009/02/17/xslt-reports-part-2/

If the XSL transformation is not what you need, please download scripts from the following location. You will find there information how to iterate entities and other objects:

http://modeling.inside.quest.com/kbcategory.jspa?categoryID=35

Regards,

Vaclav


#3

Thanx, I’ll check out these templates.


#4

I prefer JScript scripting.
Iterating over all entities and attributes seems easy.
But how to generate the output?
With Log.Information my code goes to the log, that can be exported, but with date and time prefix. Not very comfortable…
I’d prefer to open a window with a textbox where I could copy’n’paste the result.
How could this be achieved?

I found the scripts for DDL generation, there DDLScript.WriteLine is used. Is this the right way to go?

Is there an easy way to just open a file and write my output to this file?

I cannot find any documentation for scripting that answers such questions?!
Where can I find a documentation about available predefined objects and obejcts like System, Application, Log e.g.?

Thanx a lot
Andreas


#5

Hi Andreas,

Yes, there is a very easy way how to create a new text stream to write content into it and save it. You can create instead of a text file also a XML document easily. Below is a simple script that creates one text file and one xml file and fills it with a list of entities.

function main()
{
var app = System.GetInterface(‘Application’);

  •     //... parameter in GetObject determines with which model the script should work.
       //0 = first model listed in the Application View, 1 = second model listed in the Application View etc.*
    
       var Model = app.Models.GetObject(0);
    

// sample #1: writing entity names into a UTF text file
// create a text stream

     var TextStream = System.CreateObject( "TextStream" );
     TextStream.FileName = "C:\\TestTextOutput.txt";
     for (e=0; e<Model.Entities.Count; e++)
     {
         Entity = Model.Entities.GetObject( e );
         TextStream.WriteLine( Entity.Name );
     }   
     TextStream.SaveToFile();
  •     // sample #2: writing entity names into a XML file
       // create a DOM object*
    
       var xmlDoc = new ActiveXObject( "Msxml2.DOMDocument.3.0" );   
       var EntNodes = xmlDoc.createElement( 'Entities' );
       var EntNode;
      
       for (e=0; e<Model.Entities.Count; e++)
       {
           Entity = Model.Entities.GetObject( e );
           EntNode = xmlDoc.createElement( "Entity" );
           
           EntNode.text = Entity.Name;
          
           EntNodes.appendChild( EntNode );
       }   
       xmlDoc.appendChild( EntNodes );
       xmlDoc.save( "C:\\TestXMLOutput.xml" );
    

}

I think this script is very easy to understand, but if you should have any questions don’t hesitate to ask.

David

Message was edited by: DavidF


#6

Perfect! Thanx a lot.
This support forum is so fantastic and it’s a great product!
Way to go!

Andreas