Graham Graham - 8 months ago 47
Node.js Question

How do you apply a filter at runtime with a node.js Azure Function hitting Table Storage?

I'm writing an Azure Function to access multiple records in Azure Table Storage and want to apply my filter at runtime with a variable passed in to a WebHook. I have successfully run my Function with the filter in function.js, but don't see anything in the docs on how to apply the filter inside index.js.

I tried this, but it had no effect on the entities returned. This same filter works correctly inside function.js.

context.bindings.inputTable.filter = 'name eq "test"';

Answer Source

You can't construct and set the filter in your function code. We do have an open issue here in our repo tracking support for more dynamic binding scenarios, which would enable this.

However, the function.json filter expression does support binding parameters, so if the parameters are part of the JSON payload coming in on the WebHook you can use them in your query. For example, if your payload contains properties region of type string and status of type int you can define a filter like "(Region eq '{region}') and (Status eq {status})" and the filter executed at runtime will be bound to the incoming values.