Loop - Windows

Declaration

<AMLOOP ACTIVITY="windows" RESULTVARIABLE="text" ALLOWHIDDEN="YES/NO" INCLUDE="text" EXCLUDE="text" WINDOWHANDLEVARIABLE="text" RESULTDATASET="text" SORT="text (options)" />

Related Topics   

Overview

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 are retrieved or when a Break is encountered.

Practical usage

Ideally used to perform operations on more than one window open on the system.

Parameters

General

 
PropertyTypeRequiredDefaultMarkupDescription
Store window title in variableTextYes(Empty)RESULTVARIABLE="varname"The name of an existing variable to populate with the current window title upon each successive loop.
Include hidden windowsYes/NoNoNoALLOWHIDDEN="yes"If selected, invisible (or hidden) windows are included in the loop results.

Advanced

 
PropertyTypeRequiredDefaultMarkupDescription
Include WindowsTextNo(Empty)INCLUDE="*Microsoft Edge"

If enabled, specifies a wildcard mask to designate the titles of windows to include in the loop. Supported wildcard characters are:

  • Asterisk (*) - Represents zero or more characters in a string of characters. For example, if *.
  • Question mark (?) - Represents any character. For example, if *Microsoft Edge is specified, the loop includes all window titles ending with the text Microsoft Edge.
  • Pipe (|) - Represents any string of entered titles. For example, if *example1*|*example2* is specified, the loop includes all window titles containting example1 or example2.
Exclude WindowsTextNo (Empty) EXCLUDE="*Microsoft Edge"

If enabled, specifies a wildcard mask to designate the titles of the windows to exclude from the loop. Supported wildcard characters are:

  • Asterisk (*) - Represents zero or more characters in a string of characters.
  • Question mark (?) - Represents any character. For example, if *Microsoft Edge is specified, the loop excludes all window titles ending with the text Microsoft Edge.
  • Pipe (|) - Represents any string of entered titles. For example, if *example1*|*example2* is specified, the loop excludes all window titles containting example1 or example2.
Store window handle in variableTextNoDisabledWINDOWHANDLEVARIABLE="Var1"If enabled, indicates the name of the variable to populate with the current window handle upon each successive loop. This parameter is disabled by default.
Create and populate datasetTextNoDisabledRESULTDATASET="theDataset"If enabled, indicates the name of a dataset to create and populate 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 presortingText (options)NoNone
  • SORT="none"
  • SORT="ascending"
  • SORT="descending"
Specifies if a sort order is applied to the window titles before loop begins. The available options are:
  • Do not sort list - No sorting is performed.

  • Sort the list in ascending alphabetical order - Sorting is in ascending alphabetical order from A-Z.

  • Sort the list in descending alphabetical order - Sorting is in descending alphabetical order from Z-A.

Description

Error Causes

On Error

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 executed query. For example if the following query is executed,

SELECT firstname, lastname, company from customer where city='Los Angeles';

Then the following dataset is 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 can combine two fields together:

%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 looks similar to the following:

<AMMESSAGEBOX MESSAGETEXT="%datasetname.firstname%" WINDOWTITLE="The firstname of the current record is"

At runtime, %datasetname.firstname% is replaced by the contents of the subject of the current record.

The following activity creates a dataset with the following fields (assuming the name of the dataset is theDataset):

NameData TypeReturn Value
theDataset.TitleTextThe window title.
theDataset.HandleNumberThe window handle.
theDataset.ClassTextThe window class.

There are standard fields included in every dataset. The following table describes these fields (assuming the name of the dataset is theDataset):

NameData TypeReturn Value
theDataset.CurrentRowNumberThe current row accessed in the dataset by an expression that does not contain a specific row index.
theDataset.TotalRowsNumberThe total number of rows in the dataset
theDataset.TotalColumnsNumberThe total number of columns (not including the static columns) in the dataset.
theDataset.ExecutionDateDateThe date and time the dataset is created and populated
theDataset.RowsAffectedNumberThe number of rows affected by an update.
theDataset.SQLQueryTextThe SQL Query used to generate this dataset. If a SQL Query is not used, this value is empty.
theDataset.DatasourceTextThe datasource used for the SQL Query, if applicable.
theDataset.ColumnNamesTextA 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 percent signs (%). For example, %myVariable% or %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by clicking theInsert expression/variable button or by pressing F2 on your keyboard.

More on variables
More on expressions

More on the Expression Builder

Example

NOTE:
  • 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 Microsoft Edge in its title. A message is displayed during each successful iteration, displaying the title of the current window.

Copy
<AMVARIABLE NAME="theTitle" VALUE="" />
<AMLOOP ACTIVITY="windows" RESULTVARIABLE="theTitle" EXCLUDE="*Microsoft Edge*" 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 Microsoft Edge in its title.

Copy
<AMVARIABLE NAME="theTitle" VALUE="" />
<AMLOOP ACTIVITY="windows" RESULTVARIABLE="theTitle" EXCLUDE="*Microsoft Edge*" SORT="ascending" />
<AMWINDOW ACTIVITY="close" WINDOWTITLE="%theTitle%" />
<AMLOOP ACTIVITY="end" />