Skip to main content


 

Symptoms


SYMPTOMS
For Each cycle with one If condition works correctly but when trying to add Else into this cycle error appears:

“An Else block must follow an If block or an Else-If block. An Else block may not follow an Error, Else or For Each block.”

Due to this error message view cannot be saved. It is also not possible to move Else one level up (branch moves higher outside of For Each cycle), it is also not possible to add second If into For-Each cycle (it can be added only after or before it).

Is it possible in LV/ELV to implement For-Each cycle with branching (If-Else, If-If- … -Else) inside of the cycle depending on defined conditions?
For example, suppose it is necessary to do the following for each selected entry in the list:
If status is “draft” and current user is creator/author of entry then delete
If status is “draft” and current user is NOT creator/author of entry then – display a message “You do not have access for deletion”
Else – display a message that only drafts can be deleted.
For Each cycle with one If condition works correctly but when trying to add Else into this cycle error appears.
 

Diagnoses


To implement such scenario you can configure your rules as follows:

When a button is clicked
IF tStatus] = 'Draft' AND Creator] = 'System User Name'
Delete item
ELSE
IF Status] = 'Draft' AND Creator] <> 'System User Name'
Show Message: You do not have access to delete this item
ELSE
IF Status] <> 'Draft'
Show Message: Only Draft items can be deleted
In order to implement For Each cycle with aforementioned rules setup 2 buttons are necessary, the first - Delete Item (with rules described above) and the second which runs For Each cycle Execute Another Rule.

Or alternatively additional loop can be used with an opposite IF condition as this allows to get the same result. Example:
For Selected rows
If an advanced condition is true // in this condition you might check X1=A1 and X2=A2
Do your stuff
For Selected rows
If an advanced condition is true // in this condition you would check X1 != A1 OR X2 != A2 (an opposite condition to the first one)
Do your else stuff
 

Resolution

Two possible solutions described above.




 
Be the first to reply!

Reply