As mentioned in the comments, it's hard to know for sure what's happening based on the partial script. However, I can explain why a console.log
statement might change the script behavior.
Behind the scenes, Office Scripts is trying to batch read/write operations. This reduces the number of calls to the workbook (particularly important when using Excel on the web). However, if your script needs the data being read, the batch runs with whatever it has at that point - synchronizing the local client and the workbook. console.log
statements always force a sync.
The exact batching mechanics are intentionally obfuscated, but the article Improve the performance of your Office Scripts talks about this behavior from a performance perspective. Might provide some insight.
It's possible you've uncovered a bug in Office Scripts. Iterating over a filtered map might not be syncing the data correctly (and the log statement is forcing the sync at a different time). If that's the case, please send feedback through the in-client help.