Hi Everyone,
I’m trying to check the confidence score of each field from ExtractedResult and if the score is below 0.7 then I’m throwing a business exception, but if there is no data extracted for any particular field then I’m getting an error as “If: Index was outside the bounds of the array.”
please see the below screenshots for more details:
I also tried item.value(0) isNot Nothing, but still getting same error.
How to handle if item.values(0) is Empty?
If anyone knows how to handle this scenario, please help…
that’s your IF condition that is trying to access an element which doesn’t exists.
before using the element of array, check the length of that array.
You can check, if the value is not there, what is the number of array elements in array and then put a if condition to check array length and accordingly proceed
The issue is the element was not there, as there were fewer data field extracted → that array had less element and hence the index @Nitesh_Rajput was trying to use was not found as it was not there)
Below is the same error if we use the string.IsNullOrEmpty(
Here is what I interpret from the problem statement:
Results are extracted for few columns and for few not extracted (which is common wrt Doc processing).
Where it is extracted, it works fine, but for columns where its not extracted, it throws error.
Now when result is not extracted for particular column , can be checked using isnullorempty in my view.
Appreciate your clarification! May be you wanted to mention using that syntax before the IF?
You are absolutely correct with this, but if we are looping through the values then the fields will not have any element to check on, item.value will be NULL
but item.value(0) will not exists, hence checking this for NULL will again throw the ugly red colored sentence.
Hence we ideally check if the value exists that can also be done with the help of syntax you mentioned but not for the array element of the current item’s value, it should be for the current item’s value