Loop - Windows
Declaration
<AMLOOP ACTIVITY="windows" RESULTVARIABLE="text" ALLOWHIDDEN="YES/NO" INCLUDE="text" EXCLUDE="text" WINDOWHANDLEVARIABLE="text" RESULTDATASET="text" SORT="text (options)" />
Description
Loops through all of the Windows that are currently open on the system. The variable specified is updated with the current window title. With each successive loop, the next window title is retrieved. The loop ends after the window title of all the open windows have been retrieved or when a Break is encountered.
Practical usage
Ideally used to perform operations on more than one window that is open on the system.
Parameters
General
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Store window title in variable | Text | Yes | (Empty) | RESULTVARIABLE="varname" | The name of an existing variable to be populated with the current window title upon each successive loop. |
Include hidden windows | Yes/No | No | No | ALLOWHIDDEN="yes" | If selected, invisible (or hidden) windows will be included in the loop results. |
Advanced
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Include Windows | Text | No | (Empty) | INCLUDE="*Explorer" | If enabled, specifies a wildcard mask to designate the titles of windows to be included in the loop. Supported wildcard characters are:
|
Exclude Windows | Text | No | (Empty) | EXCLUDE="*Explorer" | If enabled, specifies a wildcard mask to designate the titles of the windows to be excluded from the loop. Supported wildcard characters are:
|
Store window handle in variable | Text | No | Disabled | WINDOWHANDLEVARIABLE="Var1" | If enabled, indicates the name of the variable that should be populated with the current window handle upon each successive loop. This parameter is disabled by default. |
Create and populate dataset | Text | No | Disabled | RESULTDATASET="theDataset" | If enabled, indicates the name of a dataset to be created and populated with data about each window being looped. In addition to the standard dataset fields, this dataset contains specific action specific fields entered below under Datasets. This parameter is disabled by default. |
List presorting | Text (options) | No | None |
| Specifies
whether a sort order should be applied to the window titles before
loop begins. The available options are:
|
Additional notes
Datasets
A dataset is a multiple column, multiple row container object. For example, in a SQL- Query action, the fields contained within the created dataset are determined by the query that was executed. For example if the following query is executed:
SELECT firstname, lastname, company from customer where city='Los Angeles';
Then the following dataset would be generated (where datasetname specifies the name of the dataset):
datasetname.firstname
datasetname.lastname
datasetname.compan
A record (row) is created for each record (row) that is retrieved from the server. To access this data use the Loop - Dataset activity to loop through the records, inside the loop you can extract the data from the field of your choice (from the current record) by using an embedded expression such as the one that follows:
%datasetname.firstname%
or you could combine two fields together like this:
%datasetname.firstname + " " + datasetname.lastname%
Embedded Expressions such as these can be used in any parameter in any action. So, to display the data in a message box the AML code would look like this:
<AMMESSAGEBOX MESSAGETEXT="%datasetname.firstname%" WINDOWTITLE="The firstname of the current record is"
At runtime the text %datasetname.firstname% is replaced by the contents of the subject of the current record.
This activity creates a dataset with the following fields (assuming the name of the dataset is theDataset):
Name | Data Type | Return Value |
---|---|---|
theDataset.Title | Text | Returns the window title. |
theDataset.Handle | Number | Returns the window handle. |
theDataset.Class | Text | Returns the window class. |
There are standard fields included in every dataset. The table below describes these fields (assuming the name of the dataset istheDataset):
Name | Data Type | Return Value |
---|---|---|
theDataset.CurrentRow | Number | The current row that will be accessed in the dataset by an expression that does not contain a specific row index. |
theDataset.TotalRows | Number | The total number of rows in the dataset |
theDataset.TotalColumns | Number | The total number of columns (not including the static columns) in the dataset. |
theDataset.ExecutionDate | Date | The date and time the dataset was created and populated |
theDataset.RowsAffected | Number | The number of rows affected by an update. |
theDataset.SQLQuery | Text | The SQL Query that was used to generate this dataset (If a SQL Query was not used, this value is empty). |
theDataset.Datasource | Text | The datasource used for the SQL Query, if applicable. |
theDataset.ColumnNames | Text | A comma-delimited list of the column names in the dataset |
Variables and expressions
All text fields allow the use of expressions, which can be entered by surrounding the expression in percentage signs (Example: %myVariable% or %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by clicking theInsert expression/variablebutton or pressingF2.
More on variables
More on expressions
More on the Expression Builder
Example
- Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
- To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.
Example 1
Loop Windows action used to loop all open windows in alphabetical order excluding windows that contain the text Internet Explorer in its title. A message box is displayed during each successful iteration displaying the title of the current window.
<AMVARIABLE NAME="theTitle" VALUE="" />
<AMLOOP ACTIVITY="windows" RESULTVARIABLE="theTitle" EXCLUDE="*Internet Explorer*" SORT="ascending" />
<AMSHOWDIALOG>A Window titled "%varTitle%" is currently open</AMSHOWDIALOG>
<AMLOOP ACTIVITY="end" />
Example 2
Loop Windows and close all windows that contain the text Internet Explorer in its title.
<AMVARIABLE NAME="theTitle" VALUE="" />
<AMLOOP ACTIVITY="windows" RESULTVARIABLE="theTitle" EXCLUDE="*Internet Explorer*" SORT="ascending" />
<AMWINDOW ACTIVITY="close" WINDOWTITLE="%theTitle%" />
<AMLOOP ACTIVITY="end" />