Gabriel Gomes
Gabriel Gomes

Reputation: 35

Return the entire query if the filter is empty in phonograph2

I am trying to make a date filter within the query in phonograph so that if the date filter is empty it returns the entire query

enter image description here

Preview Rendered Query

enter image description here

However, I am not very familiar with the language, I am not able to do it correctly and it is generating this error

enter image description here

Could someone who is more familiar with the language explain me where I am going wrong and teach me how to make the entire query return if the filter is empty or null

Upvotes: 0

Views: 148

Answers (1)

tnguyen.engineer
tnguyen.engineer

Reputation: 46

I recommend using the following code block to apply a range filter. Specifically if you only need the one range filter, and not multiple filters, this should be the simplest solution

{
  "tableRids": [
    "{{f_getTableId}}"
  ],
  "filter": {
    "type": "range",
    "range": {
      "field": "your_field_name",
      "gte": "your_value"
      "lte": "your_other_value"
    }
  }
}

In your rendered request as well, the input variable {{inicio_input.value}} is currently rendering to an empty string. This would not return a valid response when trying the query, so when testing it I recommend putting in some test values like 1 and 10 or other range that you expect would return a non zero result.

Final note - the matchAll block is only used if you want to return all rows with this table an aggregate them. In your case, it looks like you just want to apply a filter, in which case the above code should work.

Query examples can be found on the docs here - https://www.palantir.com/docs/foundry/slate/references-writeback/#query-examples

Upvotes: 0

Related Questions