This is the sample text.
170766123,itemA66373216
188059977,itemA01502409
169498025,itemA48202024
147855226,itemA11666073
I have a text file that i need to move the first row to the last row.
My problem was im getting an output of comma and the value of first row was missing.
I have attached a photo of sequence and sample text.
@craigmartin
can you share the output of generate datatable activity
@craigmartin
@Karan28 Check this workflow :
ShiftRows.xaml (8.9 KB)
What I have done is :
Get the Row having Total in it’s First Column
Convert the Row to Object Array and Store it.
Delete the Total Row from the Datatable.
Use Add Data Row Activity with Object Array as the input value which in turn contains the total row value.
Let me know if it doesn’t work.
check the thread as reference
rlgandu
(Rajyalakshmi Gandu)
February 6, 2024, 5:31am
4
@craigmartin
dt.AsEnumerable().Skip(1).Concat(dt.AsEnumerable().Take(1)).CopyToDataTable()
Output:
Column1,Column2
188059977,itemA01502409
169498025,itemA48202024
147855226,itemA11666073
170766123,itemA66373216
1 Like
This is the output of generate datatable activity.
rlgandu
(Rajyalakshmi Gandu)
February 6, 2024, 5:38am
7
@craigmartin
Can you try my approach hope it will meet your requirement
@craigmartin
[image]
dt.AsEnumerable().Skip(1).Concat(dt.AsEnumerable().Take(1)).CopyToDataTable()
Output:
Column1,Column2
188059977,itemA01502409
169498025,itemA48202024
147855226,itemA11666073
170766123,itemA66373216
Thank you I will look into that.
rlgandu:
@craigmartin
dt.AsEnumerable().Skip(1).Concat(dt.AsEnumerable().Take(1)).CopyToDataTable()
Output:
Column1,Column2
188059977,itemA01502409
169498025,itemA48202024
147855226,itemA11666073
170766123,itemA66373216
I’m new to UiPath can you explain about your code how it works? I haven’t tried yet because it really advance to me.
Thank you I will looked into your share. Can you explain why my sequence was incorrect and giving me an output of a comma.
rlgandu
(Rajyalakshmi Gandu)
February 6, 2024, 6:03am
9
@craigmartin
dt.AsEnumerable().Skip(1).Concat(dt.AsEnumerable().Take(1)).CopyToDataTable()
dt.AsEnumerable(): Converts the DataTable dt into an enumerable collection of DataRow objects.
Skip(1): Skips the first row of the collection.
Concat(dt.AsEnumerable().Take(1)): Concatenates the remaining rows with the first row from the original DataTable.
CopyToDataTable(): Converts the concatenated collection of DataRow objects back into a new DataTable.
The resulting DataTable now has the first row moved to the last position.
@craigmartin
i think the sequnece which you have implememented was correct.
can you debug the process by placing break points and check the output after each activity,So that you can figure it out where it went wrong?
Thank you for detailed information highly appreciated.
Shiva_Nikhil:
@craigmartin
i think the sequnece which you have implememented was correct.
can you debug the process by placing break points and check the output after each activity,So that you can figure it out where it went wrong?
The first row output is for assign: firstRow = dtFileContent.Rows(0)
The second row output is for Remove Data Row Activity.
The third row is after Add Data Row Activity.
My question is why is the firstRow value deleted even we assign to a variable?