Home > Forum > Plugins > Don't understand Foreach / For aach Action

Don't understand Foreach / For aach Action
0

Hi there.

Trying to familiarize myself with the for each action.

I have an item list an I want a business rule to evaluate the value for each row of a certain column (choice field) an execute an action for it.
Unfortunately, as soon as I have more than one row in the item list, the BR evaluation will fail as it attempts to test against all the row values for the specified column.

My BR uses:

IF[GET IDs[SELECT VALUES[Item list | Column]]] = [Choice field id]

I guess there must be something wrong with SELECT VALUES as this probably retrieves all the row values.
However, in a business rule the functions to iterate over item lists don't exist like they do for form rules.

Any tips on how to evaluate each row value in a business rule and perform an action based on the result?

Thanks for your help.

MVP

Hi Flo,

do you want to use the for each row function in a form rule or the for each operator in an automation:
The later one is documented here:
https://community.webcon.com/posts/post/for-each-operator/319/3

If it's in the form rule you can use the get row value function.

Select values will return all values from all rows therefore this will probably not work as intended.

If you need more information feel free to write a bit more about your case.

Best regards,
Daniel

In reply to: Daniel Krüger (Cosmo Consult)

Hi Flo,

do you want to use the for each row function in a form rule or the for each operator in an automation:
The later one is documented here:
https://community.webcon.com/posts/post/for-each-operator/319/3

If it's in the form rule you can use the get row value function.

Select values will return all values from all rows therefore this will probably not work as intended.

If you need more information feel free to write a bit more about your case.

Best regards,
Daniel

Hi Daniel,

thanks for the link.
The guide shows how to start a sub-Wf with For Each.
I'm looking to do something with each row from an item list with an Active Directory Action plus an Update Related Workflow Instance Action (See Screenshot)

The item list contains a column named 'Mkz'. This I want to use to write to AD and update the related Wf-instance.
So, I thought I could iterate through each row and grab each row's value with SELECT VALUES.
Unfortunately, and as you confirmed, this collects all 'Mkz' values from all rows.
This means that if I only had one row, it all works as intended. But as soon as I add another both actions will attempt to update the AD field ad related Wf field with multiple values.
And this is the main issue.

Moreover, the values I'm mapping to the fields for these two actions are determined by business rules. They work with SELECT VALUES but like we said, only for the first row.

BR evaluate one column of the item list and if it matches a value (like 0 or 1) then another item list column value will be returned which is the one to be used for the AD and update related Wf-instance actions:
IF[GET IDs[SELECT VALUES[Item list | Column]]] = [VALUE] THEN [GET IDs[SELECT VALUES[Item list | Column]]]

Long story short, how can I get the For Each action to use the business rule to return only the current row's value instead of pooling them?

Hope that helps.

Thanks for your help.

Hope that helps.

P.S. I can only ever attach one screenshot, is that right?

MVP
In reply to: Flo

Hi Daniel,

thanks for the link.
The guide shows how to start a sub-Wf with For Each.
I'm looking to do something with each row from an item list with an Active Directory Action plus an Update Related Workflow Instance Action (See Screenshot)

The item list contains a column named 'Mkz'. This I want to use to write to AD and update the related Wf-instance.
So, I thought I could iterate through each row and grab each row's value with SELECT VALUES.
Unfortunately, and as you confirmed, this collects all 'Mkz' values from all rows.
This means that if I only had one row, it all works as intended. But as soon as I add another both actions will attempt to update the AD field ad related Wf field with multiple values.
And this is the main issue.

Moreover, the values I'm mapping to the fields for these two actions are determined by business rules. They work with SELECT VALUES but like we said, only for the first row.

BR evaluate one column of the item list and if it matches a value (like 0 or 1) then another item list column value will be returned which is the one to be used for the AD and update related Wf-instance actions:
IF[GET IDs[SELECT VALUES[Item list | Column]]] = [VALUE] THEN [GET IDs[SELECT VALUES[Item list | Column]]]

Long story short, how can I get the For Each action to use the business rule to return only the current row's value instead of pooling them?

Hope that helps.

Thanks for your help.

Hope that helps.

P.S. I can only ever attach one screenshot, is that right?

Hi Flo,

maybe these information will help you:

The numbers refer to the number in the screenshot
In the for each action you can select different types, in my case the item list is unfortunately called "Item list" (1).
In the for each action you have access to the columns/fields of in each action using the values tab. For example:
I want to update a column in the item list.
I have to use the action "change action of a single field" (2).
In the action I can select the field which should be updated and I'm using the value of "column 3" which is now available in Values\Form fields (3). Which are only visible in a for each action.

This way there's no need for a custom business rule.

Regarding the screenshots.
The workaround is to edit the post again, than you can add a new screenshot.


Best regards,
Daniel

In reply to: Daniel Krüger (Cosmo Consult)

Hi Flo,

maybe these information will help you:

The numbers refer to the number in the screenshot
In the for each action you can select different types, in my case the item list is unfortunately called "Item list" (1).
In the for each action you have access to the columns/fields of in each action using the values tab. For example:
I want to update a column in the item list.
I have to use the action "change action of a single field" (2).
In the action I can select the field which should be updated and I'm using the value of "column 3" which is now available in Values\Form fields (3). Which are only visible in a for each action.

This way there's no need for a custom business rule.

Regarding the screenshots.
The workaround is to edit the post again, than you can add a new screenshot.


Best regards,
Daniel

Hey Daniel,

thanks.
With not using a business rule but the values from the Values tab it indeed uses single values.
However, it only ever uses the latest row's value.

For example, if I have two rows in the item list, the AD action to update a user, as well as the one to update the related Wf instance will not set the first row's value.
I verified this with simply using a multiple lines field (append mode) and send an email with the row's column value. It's always the latest one but the For Each action iterates through all item list rows as I'm getting two values in the field and two emails.

Can you reproduce this?

Thank you!

MVP
In reply to: Flo

Hey Daniel,

thanks.
With not using a business rule but the values from the Values tab it indeed uses single values.
However, it only ever uses the latest row's value.

For example, if I have two rows in the item list, the AD action to update a user, as well as the one to update the related Wf instance will not set the first row's value.
I verified this with simply using a multiple lines field (append mode) and send an email with the row's column value. It's always the latest one but the For Each action iterates through all item list rows as I'm getting two values in the field and two emails.

Can you reproduce this?

Thank you!

Hi Flo,

maybe I'm missing something obvious to understand your issue, because I really can't wrap my head around what you want to do or why there should be an issue. Of course I don't have your actual workflow but even with the simple mail example I don't see any problem.

I've created a simple workflow with an item list, with a column CurrentRowValue, which was called "Source column" before.
I added three rows. (1)
I added a for each operator and in this operator I changed the value of two multi line fields one in append mode the other one in standard. The change is, that the value from (2) the current row is added to the existing value.
Executing the actions results in the expected values (3), The values make up the value of the standard multi line field and there are three entries for the append mode one.
The mail action which is also part of the for each operator generates three mails. Each of these is displaying the value valid for the actions /rows executed up to the execution of the mail action itself.

So everything works as I would expect it. If "for each" operator is used, than all actions will be executed for each row. The modified values will be used by the subsequent actions.
Any actions outside /after the "for each" operator will use the final values.


Best regards,
Daniel

In reply to: Daniel Krüger (Cosmo Consult)

Hi Flo,

maybe I'm missing something obvious to understand your issue, because I really can't wrap my head around what you want to do or why there should be an issue. Of course I don't have your actual workflow but even with the simple mail example I don't see any problem.

I've created a simple workflow with an item list, with a column CurrentRowValue, which was called "Source column" before.
I added three rows. (1)
I added a for each operator and in this operator I changed the value of two multi line fields one in append mode the other one in standard. The change is, that the value from (2) the current row is added to the existing value.
Executing the actions results in the expected values (3), The values make up the value of the standard multi line field and there are three entries for the append mode one.
The mail action which is also part of the for each operator generates three mails. Each of these is displaying the value valid for the actions /rows executed up to the execution of the mail action itself.

So everything works as I would expect it. If "for each" operator is used, than all actions will be executed for each row. The modified values will be used by the subsequent actions.
Any actions outside /after the "for each" operator will use the final values.


Best regards,
Daniel

Hi Daniel,

thanks for your test results.

I believe I found the error.
Once I removed the business rules it works correctly.

Let me explain the actual requirement I have.

I have three item list columns 'mobile', 'info' and 'public'.

The goal is to write the AD user's mobile number to the corresponding 'mobile' AD property IF the item lists 'public' column's value is 1.
IF the 'public' value is 2 the 'mobile AD property should remain empty.

For the second AD property 'info', it should contain 'mobile public' IF the item list column field 'public' is 1 and 'not public' if it is 2.

So like we've established, the For Each action works with the actual item list values for each row.
However, I think I need two business rules to establish the correct values for the AD property fields.

And as the business rules I used the ones I already mentioned:

IF[GET IDs[SELECT VALUES[Item list | Column]]] = [VALUE] THEN [GET IDs[SELECT VALUES[Item list | Column]]]

I hope this concrete example explains it better.

Thank you.

MVP
In reply to: Flo

Hi Daniel,

thanks for your test results.

I believe I found the error.
Once I removed the business rules it works correctly.

Let me explain the actual requirement I have.

I have three item list columns 'mobile', 'info' and 'public'.

The goal is to write the AD user's mobile number to the corresponding 'mobile' AD property IF the item lists 'public' column's value is 1.
IF the 'public' value is 2 the 'mobile AD property should remain empty.

For the second AD property 'info', it should contain 'mobile public' IF the item list column field 'public' is 1 and 'not public' if it is 2.

So like we've established, the For Each action works with the actual item list values for each row.
However, I think I need two business rules to establish the correct values for the AD property fields.

And as the business rules I used the ones I already mentioned:

IF[GET IDs[SELECT VALUES[Item list | Column]]] = [VALUE] THEN [GET IDs[SELECT VALUES[Item list | Column]]]

I hope this concrete example explains it better.

Thank you.

Hi Flo,

in this case I would do the following:

1. Create local parameters for mobile and info AD property in the automation, this can only be done inside the for each.
2. Clear the values of both parameters
3. Add the if condition as you described and set the appropriate value.

Execute the AD action using the local parameters instead of values from the item list. Since the values are cleared during each iteration only either one would be set in the if condition. Therefore you could execute the AD action.


In a more complex case I would also use a business rule instead of the if operator in the for each. I would then pass the values of the columns to the rule via parameters.

Best regards,
Daniel