Search an entire NAV database with 10 lines of code

So a friend and I talked about how to search for data in NAV across all tables, and I said, I can do that in 10 lines of code 🙂

That’s a “Show Up or Shut Up” moment. So here goes:

Here presented in an older version of NAV, just to show that this works in most versions:

The idea is simple:
1. Loop through all tables
2. For each table, create a RecordRef
3. Loop through all records in the RecordRef
4. Do a text search with STRPOS inside the FORMAT(RecordRef) text string.

The secret here is that the FORMAT command, when used on a Record or a RecordRef returns a TAB separated string with all the fields from the record.

If you want case in-sensitive search, use LOWERCASE on the SearchValue and the output of the FORMAT command.

This is not fast, optimized or anything other that very complete and only 10 lines of code 🙂