Each script is executed in a project context and that context is filled with a set of predefined objects like the well known finder instance. That finder instance is an instance of the Finder class and bound to the executing project. However, a script is not necessarily bound to just that project or just that finder instance but can also reach out to data in other projects or create more finder instances. That's when the Global object comes into play.
The Global object offers a set of functions to
- create new Finder instances
- query for other open projects in the workspace
In this topic we concentrate on the later use case. An example:
var projects = Global.getProjects();
alert("You have " + projects.size() + " open projects in your workspace");
That snippet simply uses the Global object to retrieve the project root nodes of all open projects in the workspace. The result of the function call is a list, so methods as size(), get(0) and isEmpty() are provided. Lets move on:
// create my own finder
var projectFinder = Global.getFinder(projects.get(0));
This snippet now takes the first project and creates a new finder instance. This is more or less the same code that is used to create the initial finder instance provided to the script, but now for another project.
Note that scripts have no write permission to other projects, just read permission so you can write scripts that may read data from any project in the workspace, but just can manipulate the project that it is executed in.
Finally an important note on further methods in the Global object.
var projectFinder = Global.getFinder( [projects.get(0), projects.get(1)] );
var target = projectFinder.find("name", "Item Definition");
alert(target.size());
This snippet illustrates that there is another method getFinder that accepts an array of objects or even a previous finder result. The returned finder now behaves different: all queries are only done on the objects in the array, not of any children or other content. So the script above will result in a message saying "0" because no project is named "Item Definition" even though most of them will contain a package named like that.
See the standard scripting guide for more information on the Global object. And don't hesitate to ask questions in this topic.