I need to add data column activity inside the for each loop

Hi,
I’m beginner for UI path and trying some UI automation.

I’m reading the values from excel and stored in DT1.
For Each value I’m extracting a table data and append the results in DT2.
For DT2 I need to add one more column and assign the default value as “input” variable.
Its running correctly for the first time and throwing error from the second time since the column name was already added to the DT2.

Please help me to resolve the issue.

Hi @Subramani_Rajendran

Already the Job number column is available in that datatable. It was not allow to add the same column name in the datatable by using add data column.

Before reading that excel delete the column and then try. It works.

Note : for any datatable we can’t add duplicate columns. It will throw this error.

Hope it helps!!

To handle this exception before adding the column to the datatable check the datatable contains the column name. @Subramani_Rajendran

Take an If condition to check

- Condition -> dt.Columns.Contains("Job Number")
Note - dt is the datatable variable.

→ Don’t give any activity in then block
→ Insert add data column activity in else block to add the Job Number column to datatable.

The bot go to if condition to check the Job Number column is available in datatable or not. If yes, it go to then block and don’t do anything, If no, it go to else block and add Job Number column in datatable by using add data column activity.

Hope you understand!!

Hi,

Can you try to put the following Assign activity just before ExtractTableData activity? Because it’s IN/OUT type argument and previous schema is kept unless it’s cleared. Or it might be good to change scope of the DataTable varable.

ExtractDataTable = Nothing

Regards,

@mkankatala - Thanks for the solution. But if I put “Add data column” activity in if loop then the column will write only one value.

For each search I will be getting 4 to 5 rows of table data for all line items I need to update the “Job Number” for all rows and for the second table different job number to be updated.

Please help in this scenario.

I didn’t get you @Subramani_Rajendran

Could you be elaborate whole process with some input files then only we will get understand and able to provide the solution, If possible share your workflow too.

Hope you understand!! @Subramani_Rajendran

@Yoichi
Thanks for the reply.
If I add the assign activity it will erase the extracted results of previous search.
It will write the values of last search.
But I need table values for all searches and need to write job number against each search results.

@mkankatala
Sorry for the confusion. Let me elaborate the process.

I have list of job numbers in excel and I’ll read them using read range and stored in DT1.

Then I’m using for each activity to input each job number in our ERP tool which will give me a table data (usually 4 to 5 rows) and stored the values in DT2, and it will repeat for all the job numbers.

At last, I’m writing the DT2 in excel using write range.

Here is my sample output which is working when I have one input. But when I have multiple job numbers it is not working.

Output.xlsx (8.0 KB)

Hi,

In this case, it may be better to update empty cell than using Default value.
How about the following mock sample?

ExtractDataTable.AsEnumerable.Where(Function(r) String.IsNullOrEmpty(r("Job Number").ToString)).ToList().ForEach(Sub(r)
    r("Job Number")=strData
End Sub
)

Main.xaml (15.7 KB)

Regards,

1 Like

Main.xaml (38.3 KB)
here is my workflow

Hi,

How about the following? I just added the above logic to your file.

Main(9).xaml (40.2 KB)

Regards,

Hi @Subramani_Rajendran ,

Share the screen shots what is your input and how your are expecting the output so I will create a video on it.

If you want to know who is this please refer below link.
Link:- https://youtu.be/_CkpSwRNMjM?si=be177bTRuvv29k-r
Lot of videos are there if you have explore it :blush:

Thank you…

Hi,
Still, I’m not getting proper result. It writes only the last search results.

I have 10 job numbers all needs to be searched and data to be extracted and saved to one DT then write it in excel as output.

It’s my bad. Can you try to remove the following Assign activity, then run?

image

Regards,

I did remove that one already still not working.

To isolate cause, can you try to set Breakpoint at ExtractTableData, then debug run?
Workflow will stop there, then press F11 and check the datatable has expected data?
If it’s no problem, press F11 some times and check if column is added and input data is stored?
Next Press Continue button, then check the above for the 2nd iteration.

image

@Yoichi
Thanks for your inputs.
I have found a way to add the data column.

I have added If condition and update the data row as input variable and I’m getting the expected result.

2 Likes

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