Trouble with transformer and mobile search

I'm trying to get create a fuzzy search for a list of data from a query.

I'm using a transformer to take the results of my query and search them based on the client_name field (I adapted the code from the Mobile App Tutorial).

const clients = {{ }};

const result = clients.filter(client => client.client_name.toLowerCase().includes({{clientSearch.value}}.toLowerCase()));

return result;

The transformer is giving me an error message: Error:clients.filter is not a function

I assume I'm making a bone headed javascript error somewhere but I haven't been able to figure it out. I tried the method described here Search bar query for Google Sheets to limit results - #9 by AdamG with the same results.

Any help would be appreciated.

Try assigning and then use const that works for me

const clientSearch  = {{ clientSearch.value.toLowerCase() }} 


Looks like your clients constant is not array. You may want to wrap it in formatDataAsArray function. And then formatDataAsObject back (see code below).

Also, as @iiLaw mentions, better assign clientSearch to a separate variable (I'm not sure how these transformers work myself).

So your result transformer code may look like this:

const clients = {{ formatDataAsArray(  }};
const str = {{clientSearch.value.toLowerCase() }}

const result = clients.filter(client => client.client_name.toLowerCase().includes(str));

return formatDataAsObject(result);

Woops missed that formatDataAsArray is must that's what's causing the error
Transform are a bit odd as the get triggered by any change of state of linked (or what you might call input vars/objects/query etc)

1 Like

You guys called it. The data formatted as an object was causing the problem. Using formatDataAsArray fixed it immediately.

Thanks to you both @iiLaw and @preshetin

1 Like