Smart Buttons
Controls/XML Elements

Break Loop <BreakForEach>

The BreakForEach control, which can be only used inside of the Action element, allows to break a loop.

If the BreakForEach element is used within the loop body and the condition is agreed, it stops the loop iterations and goes immediately after the loop body.

Configuring

For Break Loop, the XML code is entered directly in the Smart Buttons Editor:

  1. Open the Smart Buttons Editor to create a script.

  2. Place the cursor in the desired location for the break loop.

  3. Click Break Loop <BreakForEach> to display the code.

Examples

Example 1

Remove Notepad elements one by one. Each time, ask agents if they want to remove the first Notepad. If the agent selects No, break the loop.

For example, you can use ForLoop, where the maximum number of loops is set to 100. In this example, the <Action> is executed 100 times, if the agent continues to answer Yes. If the agent answers No, the loop breaks.

Copy
<ButtonConf ButtonName="Break For Each example" Description="" QuickCommand="">
<ForEach>
<ForStatement StartNumber="1" EndNumber="100" Step="1" />
<Action>
<RunCommand StandardCommand="True">*NP</RunCommand>
<CheckListBox Question="Do you want remove first Notepad?" Width="100" VarName="YesNo" IsRadioButton="True" SingleSelect="True" IsMandatory="True">Yes;No</CheckListBox>
<RunCommand StandardCommand="True">NP.1@</RunCommand>
<RunCommand StandardCommand="True">*NP</RunCommand>
<BreakForEach Condition="[YesNo]==No" />
</Action>
</ForEach>
</ButtonConf>

Example 2

Add an Itinerary Remark for the first three passengers. Break the loop if passenger number equals 4.

Copy
<ButtonConf ButtonName="Itinerary remark">
<Variable VarName="Passengers">%PassengersList({FirstName}/{LastName}**{PassengerNumber})%</Variable>
<ForEach>
<ElementsList>[Passengers]</ElementsList>
<Action>
<BreakForEach Condition="[@Key]==4" />
<RunCommand>RI.PASSENGER NR [@Key] is [@Value]</RunCommand>
</Action>
</ForEach>
</ButtonConf>
Nested <ForEach>

Agents can use <ForEach> inside of another <ForEach>, where the value from Parent ForEach is available to the enclosed and nested ForEach loops.

Use nested <ForEach> when you have two or more generic collections/arrays and you want to find an answer to this question:

If all/any elements from first collection satisfy the condition in all/any elements from the second collection?

<ForEach> Example

A traveler from company ABC can travel only with LO, LH, and SK carriers. The script must check if all airlines from current booking file are on the list of allowed airlines saved in BAR.

(collection1: allowed airlines, collection2: airlines from booking file)

Nested <ForEach> Example
Copy
<ButtonConf ButtonName="Nested ForEach example" Description="" QuickCommand="#FOR">
<Variable VarName="FirstLevelItems">1,2</Variable>
<Variable VarName="SecondLevelItems">1;2</Variable>
<Variable VarName="ThirdLevelItems">1;2</Variable>
<ForEach>
<ElementsList>
[FirstLevelItems]
</ElementsList>
<Action>
<Variable VarName="VariableFirst">FIRST [@]</Variable>
<ForEach>
<ElementsList>
[SecondLevelItems]
</ElementsList>
<Action>
<Variable VarName="VariableSecond">SECOND [@]</Variable>
<ForEach>
<ElementsList>
[ThirdLevelItems]
</ElementsList>
<Action>
<Variable VarName="VariableThird">THIRD [@]</Variable>
<ShowMessage Message="[VariableFirst] [VariableSecond] [VariableThird]" />
</Action>
</ForEach>
</Action>
</ForEach>
</Action>
</ForEach>
</ButtonConf>