Hi guys, I’m trying now to put the price of freight in a list or array, and then put it in a column in the Excel
Let’s name the list/array as freightProducts
I tried both actions, but both only gave me the last value, I think they’re overwriting each other?
The list/array must be a variable of String, 'cause it’s not only numbers inside it…
I think it’ll be better for it to be a list, because it’s a dynamic number of prices inside it.
The overwriting is ocurring because the iteration of the for each it’s done for an array of only one entry, when you assing arrayIndex = {valorFrete}.
What I would recommend you to do is: add data column "Frete(Convencional)" to the DataTable you read from Excel before doing the for each row. Then when you store your value insted of using a variable (valorFrete) you could assing the value directly to the DataTable using this: row("Frete(Convencional)") = valorFrete.
After the for each row, you’ll need to write the entire DataTable to excel, instead of just the last column.
Fine following with these steps in referring to the topic tagged and we discussed earlier
“now if we want to validate whether the prices is value is empty or not
–before fetching value we can use Element Exists activity and check whether there is field available ornot
the output of the Element exists activity is boolean and name it out_boolean
now use a if condition like
out_boolean = True
if yes will go to THEN part where we can fetch the value or
if not will go to ELSE part where we can assign a common value like Null”
— in the THEN part we can use a activity called add to collections
— meanwhile in the variable panel create a variable called freightproducts of type System.Collections.Generic.List(of string)
And with default value like New List(of string)
—now coming back to the add to collection in the THEN part were we can mention the collections as freightproducts and item as the variable of the get text or any other activity with which we obtained the value of freight from the URL and in the type argument mention as String
— now the values will be added to the list one by one And it won’t overwrite
Fine
— now let’s get into the part of adding that to a column in our datatable
— use a for each loop and pass the list variable freightproducts as input and change the type argument as string in the property panel of for each loop activity
— inside the use a assign activity like this Yourdatatablename.Rows(counter)(“yourcolumnname”) = item
Where
— Rows is a method of your datatable with which we can identify the rows and columns
— counter is a variable of type int32 with default value of 0 defined in the variable panel, which implies the row number (as 0 is the first index of the row)
— “yourcolumnname” is the columnname is your freightproducts column or we can even mention the column index of that column where 0 is the starting index of the first column
— now next to this assign activity use another assign activity like to increment the rows that is counter value counter = counter + 1
Simple isn’t it
Hope this would help you
Kindly try this and let know for any queries or clarification
Cheers @YuuK
It’s the same if the assign is before or after the close tab, just needs to be after the get text.
In the cases that you are setting the value manually (the ones without Get Text) you won’t need to assign it first to the variable, just assign it directly to row("Frete(Convencional)")