Back

Catch event trigger response to run function

  • 0
  • Functions
  • Cloud
oswaldogomezs
20 Oct, 2023, 19:13

Hello, people! I created a script to scrape a "notes" field on a collection, to fill some other fields. I ran this script after running another script to populate the collection. After running the second script, those documents having the proper information in the "notes" field, got the rest of fields completed (the ones that complete out of the "notes" information.). From now on, that script will be replaced with a function that triggers with every created document. The code of the bulk notes scrape script, ported to the functions specifications has been attached. However:

  1. It's necessary to catch the create document event response's document id. I'm lost at this.
  2. clean the code to update the newly created document, using the id document from the previous step as parameter on update_documents. Currently, it will process the whole collection, which it's not necessary anymore.
  3. Spot whatever pitfall that function code has. It's my first function attempt, so I expect to have overseen some things.

Thank you very much for your help

Oswald

TL;DR
The user created a script to scrape a "notes" field on a collection. They now want to replace the script with a function that triggers with every created document. They need help with 1) catching the create document event response's document id, 2) cleaning the code to update only the newly created document, and 3) spotting any issues with their function code. No solution was provided in the thread.
Drake
23 Oct, 2023, 01:54

There's a bug with 1.4.6 right now, but functions triggered by events should receive the event payload

Drake
23 Oct, 2023, 01:55

It would be in req.body

oswaldogomezs
23 Oct, 2023, 14:10

Thank you, Steven! I'm gonna test it.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more