Forum Discussion
Operation on target ForEach1 failed: The function 'length' expects its parameter to be an array
- Anonymous1 year ago
Hi Anonymous , nilendraFabric BhaveshPatel
Thanks for all your suggestions. All point to the same approach.
I solved the issue as follows.
In the Query area of the Lookup settings, I first used
select TABLE_SCHEMA as SchemaName , TABLE_NAME as TableName
From ecommerce INFORMATION_SCHEMA_TABLES
where TABLE_TYPE= 'BASIC TABLE'
This did give me thee schemaname and tablename. But did not have the option to select value array in the For Each Loop.
I changed the query to
select s.name as SchemaName,
t.name as TableName from sys.tables t
JOIN sys.schemas s on t.schema_Id = s.schema_Id Order by s.name ,t.name
This also gave me the SchemaName and TableName. And it allowed me to choose Lookuparray in the ForEach loop.
So by the above in the query solved my issue in the ForEach loop.
Another thing I observed is
In the destination screen of the Copy acitityIf I put the @item().TableName in the fileName above, it did generate the files but coluld not be previewed in the Lakehouse. And the
whas greyed out .txt and could not be changed to csv.
With the above settings the files got created with .csv extension and could be previewed.
However the file names included dbo. in the beginning of the file name.Anonymous . May be you can check with internal documentation for above behaviour.
With this I have solved my issue.
Cheers
CheenuSing
Hi Anonymous
Great question, I totally understand how this can be a bit confusing at first. The reason you're getting the error, the function 'length' expects its parameter to be an array... but got an object instead is because your Lookup activity is only returning a single row, not an array of rows and ForEach needs an array to loop over.
In your Lookup activity settings, there’s a checkbox called “First row only” this is currently enabled in your case (which is why your output shows .firstRow but not .value).
When that’s turned ON, Lookup will return a single row as an object, not an array. That’s why @activity('Lookup1').output.value doesn’t exist and throws an error.
Here’s what you can do to get it working:
- Go to your Lookup activity
- In the Settings tab, uncheck the box for “First row only”
- This will return the full list of rows as an array in the .value property
- Now, go to your ForEach activity
- For the Items field, use this expression.
@activity('Lookup1').output.value
By adding .value i think, this will allow the ForEach loop to process each row returned by the Lookup (e.g., each SchemaName and TableName) one by one.
If this response helps, consider marking it as “Accept as solution” and giving a “kudos” to assist other community members.
Regards,
Akhil.