How to compare 2 datatables and return action to be taken

New List Current List
Employee 1 Employee 1
Employee 2 Employee 2
Employee 3 Employee 3
Employee 7 Employee 5
Employee 6

Hi I have 2 datatables as shown as above, I want to compare the 2 dts and return the following result so I can update the employee list in HR system.

To remove: Employee 5, Employee 6
To add: Employee 7

You can use join Datatable activity here with inner join

  • Inner - Keep all rows from DataTable1 and DataTable2 which meet the Join rule. Any rows that do not meet the rule are removed from the resulting table.

@sophiey

Hello @sophiey

Assign

newEmployeeList = New List(Of String)(newDataTable.AsEnumerable().Select(Function(row) row("Employee").ToString())),

currentEmployeeList = New List(Of String)(currentDataTable.AsEnumerable().Select(Function(row) row("Employee").ToString())),

employeesToRemove = currentEmployeeList.Except(newEmployeeList).ToList(),

employeesToAdd = newEmployeeList.Except(currentEmployeeList).ToList(),

employeesToRemoveString = String.Join(", ", employeesToRemove),

employeesToAddString = String.Join(", ", employeesToAdd),

outputMessage = "To remove: " & employeesToRemoveString & Environment.NewLine & "To add: " & employeesToAddString

Thanks & Cheers!!!

Refer this video as per this suggestion

@sophiey

thanks for the code,

How do I convert this employeesToRemoveString and employeesToAddString to a dt so that I can loop the dt and do the updating in hr system (remove or add the employee).

@sophiey

  1. Initialize the strings and split them into arrays.
  2. Create DataTables for employees to remove and employees to add.
  3. Use a For Each loop to populate the DataTables with employee names.
  4. Implement your HR system update logic based on the DataTables.

Kartheek, would appreciate if you could help on the initialization part

@sophiey

can you refer this once

Sequence5.xaml (13.0 KB)

Hi, i cant download the doc due to org’s policy. do you mind if u can share the code here instead? thanks

Hi,

Just try this one
First use the left join in the join data table it keeps all the data in the first dt and keep the matched values in the both dt.
so its return like this

and use the output of the join dt in the for each dt and use assign activity
CurrentRow(“List_2”)=CurrentRow(“List_1”).ToString.
so final result like this


hope it will work.
thanks.

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