Assign each row to dictionary

Hey everyone.

I have a table with 2 columns, first column is ‘Machine’ and the second one is ‘TotalTime’

I want to be able to call the value corresponding to each type, so I decided to collect these in a dictionary.

So when I call dicVariable(“motor”) I want to get the total time of motor.

How can I do the for each loop?
Thank you

Hi @berkaykor,

Your query is to retrieve the values appropriate to each motor, kindly follow the below steps,

  • Declare a variable of type int, sum_TotalTime with value as 0.
  • Use for each row in a datable activity, and in the input variable pass the table variable value into it.
  • Inside the loop, use assign activity to assign the values into a variable like
    str_Machine = CurrentRow(“Machine”)
    int_TotalTime = Current(“TotalTime”)
  • Finally, in the same loop, use another assign activity to sum the values of the totaltime and storing them into the sum variable.
    sum_TotalTime = sum_TotalTime + int_TotalTime
  • Outside of the loop, you will get the total time of the motor.

Hope, this helps to solve your problem. If so, kindly mark it as solution which would be helpful for others.



Hope the following sample helps you.

dicVariable(CurrentRow("Machine").ToString)  = CurrentRow("TotalTime").ToString

We can also achieve it using LINQ without ForEachRow as the following.

dicVariable = dt.AsEnumerable.ToDictionary(Function(r) r("Machine").ToString,Function(r) r("TotalTime").ToString)

Sample (both workflows) (9.2 KB)


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.