From wiki.ginstr.com
Jump to: navigation, search

gn:act_forEach

Description
Used exclusively with variables of rows, rowsColumn, pictures, email datatypes, to repeat the execution of commands, for each element in the list parameter
Action returns
void
Controlling action
gn:act_break is used to stop gn:act_forEach action execution
  1. 35218

Using showProgressDialog and changeProgressDialog may lead to unexpected behavior, please use only if absolutely necessary. Currently there is no global solution for showing UI changes during action execution but there is a ticket where this is planned: ##38048. What was done in scope of this ticket is that we added additional signature to forEach which will internally show progress dialog during iterations. However it comes with some limitations, more information about new signature at wiki.

create zip and attach to ticket wiki : https://wiki.ginstr.com/index.php?title=gn:act_forEach&action=edit&section=1

Action signatures

Full signature

[gn:act_forEach]|[source,column,progressDialogMessage,progressDialogStyle,callbackWidgetWhenForEachIterated,callbackWidgetActionSet;ACTIONS]
Parameter Description
source source from where the while action is using value as expression parameter
column column name which will be internally added as parameter to source reference names in actions which will be executed in for each action.
e.g.
[gn:act_getRow]|[@variable/employee_allowedDivisions, @variable/divisionIndex;;@variable/currentDivisionText]
to
[gn:act_getRow]|[@variable/employee_allowedDivisions(divisionName), @variable/divisionIndex;;@variable/currentDivisionText]
progressDialogMessage(optional) if message is defined then progress bar dialog will appear when for each starts executing. Progress dialog will take source over which for each is iterating. Size of elements in source will represent total number in dialog, while 0 is beginning iteration number. i.e. 4-50 in progress bar would mean 4th element in source is being processed from total of 50 elements

Warning! When using progress dialog forEach must not be called in a trigger which at calling point has more actions that need to be executed after that trigger, those actions will be ignored. In addition, all actions AFTER forEach will be ignored. In order to execute actions after forEach you must define callbackWidgetWhenForEachIterated with callbackWidgetActionSet and put actions that follow there.

progressDialogStyle(optional) defines the progress dialog type. By default it's HORIZONTAL

Can be:

  • SPINNER
  • HORIZONTAL
callbackWidgetWhenForEachIterated (optional) target on which is defined callbackWidgetActionSet
  • widgetId
callbackWidgetActionSet (optional) event action set name which will be fired after all iterations of for each loop have been executed
  • hardcoded
ACTIONS list of actions which will be executed continuously until all rows are iterated

Repeat the execution of commands based on list source

[gn:act_forEach]|[source;ACTIONS]

Example

variable/listId - list used for iteration
variable/listId(rowColumnName1) - retrieving value from rowColumnName1 column of iterated row
[gn:act_forEach]|[variable/listId;[gn:act_rawWriteValues]|[tableId;column1,column2;variable/listId(rowColumnName1), +id/listRow]]

Repeat the execution of commands based on list source with defined column name

[gn:act_forEach]|[source,column;ACTIONS]

Example

@variable/employee_allowedDivisions - list used for iteration
divisionName - column name
[gn:act_getRow]|[@variable/employee_allowedDivisions,@variable/divisionIndex;;@variable/currentDivisionText] - action
[gn:act_forEach]|[@variable/employee_allowedDivisions,divisionName;[gn:act_getRow]|[@variable/employee_allowedDivisions, @variable/divisionIndex;;@variable/currentDivisionText]]

Repeat the execution of commands based on list source with defined column name and progress dialog with actions to post execute

[gn:act_forEach]|[source,column,progressDialogMessage,progressDialogStyle,callbackWidgetWhenForEachIterated,callbackWidgetActionSet;ACTIONS]

Example

@variable/allEmployeesRows - source
_id - column
@string/progressMessage - progressDialogMessage
HORIZONTAL - progressDialogStyle
@+id/exampleFrame - callbackWidgetWhenForEachIterated
gn:act_set1 - callbackWidgetActionSet
<FrameLayout
    android:id="@+id/exampleFrame"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    gn:act_set="[gn:act_forEach]|[@variable/allEmployeesRows,_id,@string/progressMessage,HORIZONTAL,@+id/exampleFrame,gn:act_set1;
                    [gn:act_setVariable]|[@variable/colorIndex,@variable/redIndex]
                ];"
    gn:act_set1="[gn:act_getVariableToWidget]|[@variable/employeesLastLogins,@+id/employeesLastLogins],
                 [gn:act_showWidgets]|[@+id/lastLoginEmployeesToday_refresh]," />