0

I am trying to query my data using my custom field of type Timestamp (created using Slicemachine). I can see that field is also defined as type Timestamp in index.json under /customtypes/mycustomtype/.

      "end_date": {
        "type": "Timestamp",
        "config": {
          "label": "End date",
          "placeholder": ""
        }
      }

However when I try to create a query with dateAfter predicate I am getting an error.

Query:

 const events = await client.getAllByType('event', {
        predicates : [
            prismic.predicate.dateAfter("document.data.end_date", new Date()) 
        ]
}

error message:

error - ParsingError: [function date.after(..)] 'Date' or 'Timestamp' field expected on line:1 col:14 in query '[[date.after(document.data.end_date, 1677426405339)]]'
[[date.after(document.data.end_date, 1677426405339)]]
             ^

Out of curiousity I tried to rewrite the same query and use the Prismic document built in field document.last_publication_date - this time, the query predicate worked as expected.

Any idea why the custom type field data types are not being interpreted correctly? Any help is appreciated.

shimon001
  • 733
  • 9
  • 24
  • Your `dateAfter` predicate looks correct, and the API supports passing `Date` objects as well. Since you are using Slice Machine, it's possible you have not yet pushed your modified Custom Type to Prismic. Could you confirm? It's also possible that the document you are querying hasn't been published since you added that field. As a result, the API may not be seeing `end_date` as a queryable field yet. You could try editing the document and republishing before trying the predicate again. – Angelo Ashmore Feb 27 '23 at 19:09
  • Hi @AngeloAshmore, thanks for your comment. I checked the JSON editor in Prismic and all the changes seem to be pushed correctly. The type of the field is shown as `Timestamp` and even after republishing the document I am unable to query it, with the same error. – shimon001 Feb 27 '23 at 20:22

0 Answers0