List/array of string overwriting

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.

Can someone help me, please?


Hi @YuuK

I think that read column activity is what you need :slight_smile:


1 Like

Thanks for the reply, but I’m still confused about what to do with that…

Can you show me a sample?

Is there a particular reason for using an array?

If not, I would recommend that if you plan to write the data to excel, you use a Datatable.

Then what you’ll have to do is for each data you we’re adding to your array, you will insert a new row to you datatable with that data

1 Like

Yes, that’s what I want, but instead of add to the array and then to datatable in a new row,
it keeps overwriting with the last data…

Can you show me a sample???

Would you mind uploading your .xaml and I’ll try to see what’s wrong?

1 Like

Main (1).xaml (26.1 KB)
dadosCelular - Copia.xlsx (8.2 KB)

Here you go!

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.

1 Like

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
— 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
— 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

1 Like

Thanks for the reply!!

Does this means using assing after the Get Text on the price of freight?
While still letting the output of the Get Text be “valorFrete”?

Or putting before each close tab from the For Each URL?

Thanks for the reply!

This would solve my problem of overwriting each other, right?

After all that, do I use add data column or write range to the datatable?

Put the assign after the get text!

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)")

Hopes this solves your problem!

1 Like

Thanks so much!!! :smile:

It did solve my problem!

Thank you everyone, for helping me :blue_heart:

1 Like

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