Storing variable names in a datatable to use in a For Each loop with IF statement

Hi everyone.

I have a lot of checkboxes on a Word Document that I’m getting the values by using the Get Attribute activity. I want to create an IF statement and do a set of steps if the value is checked. Instead of creating if statements for each variable I was wondering if its possible to create a data table which contains the names of the variables used for each checkbox and then loop through the data table and use the value from the row to then get the value of the variable? I could then write a simple For Each process and this wouldn’t need to change as I cycle through each checkbox variable.

Wasn’t sure if I could specify the row value being returned to be treated like a variable name or if it would just be text. e.g the IF condition would be something like CurrentRow.Item("VariableName’).ToString = True. The DataTable item would be an actual variable name that I could use in my statement.

Variables xannot be stored like that…instead crwate a dictioanry variable and then assign values that the values from datatable can be used in dictionary key


Store the values that you get from the ‘Get Attribute’ activity in the form of a key value pair in a dictionary. For example, if you are reading something like a gender from the word document, having two options ‘Male’ or ‘Female’ (With ‘Male’ option being checked), add an item in the dictionary with Male as the key and True to be its value. Do the same for all the checkboxes. Now loop through the dictionary and do the necessary steps as per the True or False values. Hope this helps.

Hi @Nikhil_Vernekar . I have managed to assign the values of each of the CheckBoxes to a Dictionary (String, Object) and some of the key value pairs are as follows:

chkBulkEast, True
chkBulkWest, False
chkbulkSouth, True

I have then added a ForEach referencing the Dictionary and when I do a Write Line of Item.ToString I get the Key / Value pair for the selected entry. e.g. chkBulkEast, True

What I want to do is determine via an IF activity if the Value is True, and then get the Key and do some other work.

I haven’t been able to determine how to reference just the Value, and then also extract just the Key into another variable. Should I just do an Assign of item.ToString and then use Split or some other function to break into 2 separate variables?

The disctionary you can use the below formula to get all the key value pairs which are having true in the value…Use below in assign

to filter on values - filtereddict = dict.Where(function(x) x.Value.Equals(True)).ToDictionary(Function(x) x.Key,function(x) x.Value)

to get keys related to them - filtereddict.keys


Hope this helps


How about using the For Each UI Element activity to loop through the checkboxes, within it you do your Get Attribute and then If, and within the If you do what you need to if it’s true.

Hi. Instead of filtering the list how can I get key and value of the current item in the For Each?

You can use dict.keys in the for each activity and then change type argument to string

Now…inside the loop currentitem will be the key and dict(currentitem).ToString will be the value

Hope this helps


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