Toad World® Forums

Creating re-usable scripts/functions

Hello,

can I use a script (or a function inside a script) from one package in a different package? e.g. I have a package “Liquibase Support” and I would like to use functions from there in script of the UniversalXMLReport package.

I have next to none experience with JavaScript and it’s class system, and I can’t find a way to create new classes in a package (although this seems possible because the UniversalXMLReport package seems to have done that).

Unfortunately the User guide does not explain how to create packages at all (apart from the obvious).

I’m also not sure if I need to declare any dependencies in my package. It also seems that the package dependencies must be declared when the package is created. Apparently I cannot add that later. Most of the nodes inside a package seem to be read only (exept for Scripts and Macros).

Hi,

you can call scripts from other packages this way:

ScriptName.Method();

The following sample calls method GetRandomNumber from script GetNumbers and writes result to Message Explorer:

Log.Information(GetNumbers.GetRandomNumber().toString());

Regarding custom properties and classes: right click your package in Package Explorer and choose Open Metamodel. New diagram opens and you can add properties to existing classes etc. More information can be found in User Guide, section Customization - Sample.

Regarding Dependencies and Extensions: please read the following document:
http://modeling.inside.quest.com/entry.jspa?externalID=4900&categoryID=29

And yes, most of the nodes are read only and show additional info e.g. when you edit existing form etc.

Regards,

Vaclav & TDM team

Message was edited by: vaclav

vaclav wrote:

Hi,

you can call scripts from other packages this way:

ScriptName.Method();

The following sample calls method GetRandomNumber from script GetNumbers and writes result to Message Explorer:

Log.Information(GetNumbers.GetRandomNumber().toString());

Does this work for Macros as well?

I have one macro script named GenerateChangeSet
Now from a second macro I’m calling a function in there: GenerateChangeSet.writeChangeLogStart()

But I get the following error:

Error during parse script GenerateChangeSet, so as to find ParentScript

Is there anything I need to configure in the Macro to make this work? Or does this only work for Scripts, not for Macros?

function Main(){

var App = System.GetInterface(“Application”);

var Model = App.ActiveModel;

var WS = App.ActiveWorkSpace;

var Log = System.CreateObject(“Log”);

Log.Information(Macro2.Test2());

}

Macro2

function Main(){

var App = System.GetInterface(“Application”);

var Model = App.ActiveModel;

var WS = App.ActiveWorkSpace;

var Log = System.CreateObject(“Log”);

}

function Test2()

{

return ‘Macro2’;

}

Regards,

Vaclav & Petr

Hi,

it should work for macros as well. Please make sure there is no typo in the code. You can send us the macro to modeling@quest.com and we can look into the matter.

Try the following test:

Macro1

Thanks, it was indeed an error in the called macro (I was looking at the caller to find the error)

Hi vaclav,

It’s possible to call “internal scripts” functions (#proc) from another scripts?. It’s possible to call these scripts from macros also?

jfelixhe.