Nested LINQ to get data from 1st datatable based on 2nd datatable filter in UiPath

Scenario — We have 2 datatables available, 1 datatable contains regional data and other contains a list of Valid Regions.

Everytime the bot runs it should only consider the valid regions to pull data from Regional Sheet.

Here is the sample data


Sample Data

LookUpData

Lookup Data

As you can see from the data, we only to retrieve data for ‘East’ and ‘West’ region from the first datatable. here is how you can do it

Write the Query in the Assign activity

Here is the complete video

Code Link - UiPathSamples/02 - NestedLinq at main · manojbatra071/UiPathSamples · GitHub

Youtube Video - Nested LINQ to get data from 1st datatable based on 2nd datatable filter in UiPath - YouTube

Happy Automation

Thanks
Manoj Batra

Hi @Manoj_Batra @ppr - I have very similar use case and i am trying to perform similar task using the same concept as above.

However , I am doing that in C#.

(from r in dtInputFile.AsEnumerable()
	let valid_customers=(from val in dtFiltered.AsEnumerable() let customer_code=val.Field<String>("CustomerCode") select customer_code).ToList<string>()
	where valid_customers.Contains(r.Field<String>("CustomerCode"))
	select r).CopyToDataTable()

image

There is no syntax error but its giving

Error ERROR Validation Error Internal constraint exception while running constraint with name ‘Constraint’ against activity of type Microsoft.CSharp.Activities.CSharpValue1[[System.Data.DataRow[], System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] with name 'CSharpValue<DataRow[]>'. Exception was: System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) at System.Activities.WorkflowApplication.Invoke(Activity activity, IDictionary2 inputs, WorkflowInstanceExtensionManager extensions, TimeSpan timeout)
at System.Activities.WorkflowInvoker.Invoke(Activity workflow, IDictionary2 inputs, TimeSpan timeout, WorkflowInstanceExtensionManager extensions) at System.Activities.WorkflowInvoker.Invoke(Activity workflow, IDictionary2 inputs)
at System.Activities.Validation.ActivityValidationServices.RunConstraints(ChildActivity childActivity, ActivityCallStack parentChain, IList1 constraints, ProcessActivityTreeOptions options, Boolean suppressGetChildrenViolations, IList1& validationErrors) SplitFileBasedOnCustomerCode.xaml

Could you please help here.

02 - NestedLinq.zip (89.8 KB)

try this