Issue with Array from Datatable

See below images. I read a range into a datatable and then use an assign to match column A with results from a PDF. If the result matches, then pull in column B and then column C. Column B works (office number) but column C (approver ID) gives me an error (Assign: Index was outside the bounds of the array). The code is the same for each assign just changed the column to pull in. Not sure what is wrong. If I remove the approve assign entirely, i have no errors. The +OfficeCIty+ is what I pull out of the PDF. The names match column A.

image

@atarantino index out of bond means you are try to excess that index which is not initialize.

Sorry not sure what that means. before the assign, i put a write range and double checked to make sure my datatable was pulling in everything and it does.

how do I fix this?

@atarantino Can you share you code.

GetPDFTable.xaml (36.0 KB)
Main.xaml (43.6 KB)

@atarantino ok give me few moments.

Thank you - i truly appreciate it.

@atarantino I am not able to run your code but I get point.

try this one.,
dtOfficeMapping.Select(“Office_City= '”+OfficeCity+“'”(2)(“Office_Number”).ToString

Hi @atarantino
Basically you want to get datatable col2 and you are giving index 0

unfortunately same error.

@atarantino
give me excel file i am making own and want to test it

OfficeCities.xlsx (9.4 KB)

@atarantino


GetDataFor-atarantino.xaml (6.2 KB)

Here my case its working and I found one thing, when you are matching that city which is not present it is giving error. It can be case sensitive as well

@atarantino

Sorry what is the code you used?

DataTable.Select(“Office_City= ‘”+City+“’”)(0)(“Office_Number”).ToString
DataTable.Select(“Office_City= ‘”+City+“’”)(0)(“Approver_ID”).ToString

I used your same code.
You are not getting my point. Queries are correct when you are matching that city which is not present .
your First query giving error not second one.

@atarantino please just my solution and in variable put that city name which is not present in excel and see what is happening. Then we will discuss about solution.

Hello @atarantino ,

if you are getting the result for

dtOfficeMapping.Select("Office_City = "'+OfficeCity+'")(0)("Office_Number").ToString

then you should definitely get the result with

dtOfficeMapping.Select("Office_City = "'+OfficeCity+'")(0)("Approver_ID").ToString

for this second case you might have used the office ID, for that there is not row exists in the datatable that’s why you are getting the error.
So to avoid this kind of error better to check if you are getting any row after applying the filter and then go for the value assign.
You can check using the below method.

if(dtOfficeMapping.Select("Office_City = "'+OfficeCity+'").Any,dtOfficeMapping.Select("Office_City = "'+OfficeCity+'")(0)("Approver_ID").ToString,"Approver_ID not exists in the input for the city "+OfficeCity)

Thanks,
Sanjit

I figured out where I went wrong. The problem isn’t that the city name isn’t present in the excel, the problem was that I used the same variable twice. The second time i replaced the name of hte city with the city number, so when the Approve ID assign was trying to match the city name to a city number, it failed. I created a new variable called Office number for my first assign which stores the values for all the city numbers.

@atarantino Great. Happy learning. Happy automation.