How to copy a column from one datatable to another based on a common column

datatable
activities

#1

I have two datatables with a common column name. Based on this column name i want to merge 1 of the columns from the 1st datatable to another datatable.


#2

@vvaidya @arivu96 @ovi


#3

Hi Naresh,

Have you checked these posts related to your request?
https://forum.uipath.com/search?q=merge%20datatables


#4

Hi @jamnanin,

Refer this xaml file.
JoinTables.xaml (10.6 KB)

Regards,
Arivu


#5

hi @arivu96 this xaml is working fine but when i do the same thing in another file unfortunately it doesnt work. I dont understand what i am doing wrong. where have you used the result and dt3 variable?


#6

@ovi can you help me where the result file is being used coz the invoke doesnt seem to work for other files. this is the error i get
**"Main has thrown an exception

Source: Invoke method

Message: Object reference not set to an instance of an object. This error usually occurs when using a variable with no set value (not initialized).

Exception Type: NullReferenceException

System.NullReferenceException: Object reference not set to an instance of an object.
at System.Activities.Statements.MethodExecutor.InvokeAndUnwrapExceptions(Func`3 func, Object targetInstance, Object[] actualParameters)
at System.Activities.Statements.MethodResolver.SyncMethodExecutor.BeginMakeMethodCall(AsyncCodeActivityContext context, Object target, AsyncCallback callback, Object state)
at System.Activities.Statements.MethodExecutor.BeginExecuteMethod(AsyncCodeActivityContext context, AsyncCallback callback, Object state)
at System.Activities.Statements.InvokeMethod.BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, Object state)
at System.Activities.AsyncCodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)"**


#7

Hi Naresh,

In Invoke method activity have you set the right Parameters?


#8

yes @ovi i have set similar parameters as in the xaml file


#9

Could you upload your workflow please?


#10

join table.xlsx (10.0 KB)

I have uploaded the xaml and the sample file @oviMain.xaml (9.0 KB)


#11

Your second Read Range activity has also the output datatable “dt1”. So when you set “dt2” as In parameter in Invoke method, it throws that error because it is not initialized.

So change the output in the second Read Range(“Sheet2”) to “dt2”.

Hope it helps!


#12

I cleared all that but I am still getting the error. can you please update the xaml and attach it?


#13

The issue is with the column names. Change in excel the first Id name with ID and it should work fine.
Screenshot_227


#14

thanks a lot @ovi


#15

@ovi Theres a slight problem now. The columns dont merge, instead the 2nd datatable gets added below the 1st one @arivu96