Adding a value to a list with for each (same value different row)

Hi everyone
I want to add a value to a list (or an array doesn’t matter)
by using for each row and taking the value with [row(“column name”).tostring] - its working
But I don’t know how to enter the value into the list without deleting the value inside

thank u in advance

Do you have a DataTable and want to create a list from one of the columns?

Hi
did we try with ADD TO COLLECTIONS activity where in the collections mention the list variable and in the item property mention the element you want to add and change the type argument accordingly

Cheers @dlichten

yeah exactly
I want to check if the element is equal to another element and if so add it to the list

@Palaniyappan
I didn’t tried it if u can explain it more because I never used a list

thanks again

Hi

we can do this validation in a IF condition and if true it will go to THEN part where we can use a ADD TO COLLECTIONS activity
in that activity under collections property mention as list_Variable which is of type System.Collections.Generic.List(of string) and with default value as New List(of string)

and in the item properrty mention as row(“yourcolumnname”).ToString and in the type argument property mention as string

Cheers @dlichten

1 Like

ok, so you can do with an Assign after creating a list variable like this:
MyList = (From r As DataRow In dt.Rows.Cast(Of DataRow)() Where CStr(r.Item("Codes")) ="mycode" Select CStr(r.Item("MyColumn"))).ToList

1 Like

@dlichten
lets assume the compare value is of datatype string (Other datatypes can also be handled)

yourdatatableVar.AsEnumerable.Select(function ( r ) r(YourColumnNameOrIndex).toString).Where(Function ( s ) s.Equals(YourCompareValue)).toList

returns a list(Of String) and can be used within an assign activity

1 Like

this is what I tried with the if statement


the letters that u don’t understand is hebrew its the column name

@bcorrea didn’t understand what is it that u wrote and where should I wirte it

@ppr I don’t need this condition because what I did worked…

if u need something more from my program please tell me so I could send u

thanks

Fine
may i know the issue now on using this
to check the count of elements in that list use this expression in a writeline activity like this
listvariablename.Count.ToString

Cheers @dlichten

the Add To Collection doesn’t work, this is the problem:
“Add To Collection: The property ‘Collection’ of ‘Add To Collection’ is not initialized.”
In the Collection I created this variable “PolicyNumList”
In Item i wrote this “row2(“מספר פוליסה”).ToString”
And in the TypeArgument I chose String

1 Like

aah got it
in variable panel initialize the variable like this for list variable
New List(of string) under default value field

Cheers @dlichten

in default value of PolicyNumList you can use: New List(Of String)

I wanted to ask @Palaniyappan about what he ment and then u wrote about that…

and now if I want to write all the values in that list how do I do it?

being inside the FOR EACH ROW loop, for each iteration it will add the ellements to that list which obviously means all values will be added to the list once after the validation inside the IF condition

Cheers @dlichten

I ran the program and all the values got inside the list
But I wanted only the values that from 1 for each row and not the second (outer loop)Send_Message_To_Agent_With_Taking_Details_From_DataBase.xaml (16.6 KB)
this is the program
and this is the database (but its in hebrew)
בסיס נתונים - ביטול פוליסה.xlsx (18.9 KB)

i didnt get this buddy
kindly elaborate a bit more on this pls
@dlichten

its like this
I have a customer that have couple of policies (insurances)
and I want the list to be only the policy number that connected to the same agent
and when I run the foreachrow, the if checks this and put it inside the list
but in the next run of the outer loop the agent number is changing and it will add another instance to the list that connected to the other agent

and what I want to happen is that each list will be an empth one - that only 1 agent number will be connected to the list

I just deleted the list at the of the for each row
so it gave me a clean list at the beginning of the for

whats the syntax to add list in C#