How implement 'For Each' loop inside an Assign Activity

Hello guys,

I want to implement an For-Each loop inside an Assign Activity, but I don’t know how to do it. Can someone help me, please?

HI @Leonardo_Andrade

Can you elaborate your query?

Check out the docs

Reference

image

Regards
Gokul

Hi @Leonardo_Andrade

Do you mean LINQ code that use indie the Assign activity?

This sample LINQ will used inside the Invoke VBA activity

dt.AsEnumerable.Where(Function(row) String.IsNullOrEmpty(row("Status").ToString)).ToList().ForEach(Sub(row) row("Status") = “Retrieved and added to Queue”)

Regards
Gokul

Hello @Leonardo_Andrade

It would be better if you can give more clarity on your requirement with some sample data.
If you need to do a for loop within assign activity then you will have to go with the linq expression.

Thanks

I need to form pairs with the rows of a datatable, and for each row calculate the average between the values of the column “Cmarg”.

But these line pairs are not successive, they occur every 5. For example, the first average is between lines 0 and 5, the second average is between lines 1 and 6, the third average is between lines 2 and 7, and so on. In the end, I need to create a single datatable with these results.

I was able to build a LINQ to group the table by a certain column of systems (“SIST”), being 5 systems in the case, and then take the first 2 rows of each group and calculate the average. Here’s LINQ:

pdocmosistDt.AsEnumerable.GroupBy(Function (row) row.Item(“SIST”)).Select(Function (grp) grp.CopyToDataTable).AsEnumerable.Select(Function (grp2) grp2.AsEnumerable.Take(2).Average(Function (row) CDbl(row.Item(“Cmarg”))))