Back

function event

  • 1
  • Databases
  • Functions
  • Cloud
jesuswithBigD
6 Jan, 2024, 10:02

hi, is it possible to make a function event listen to a specific attribute in document ? And how can i do it.

TL;DR
User wants to know if it's possible to make a function event listen to a specific attribute in a document. They receive suggestions to trigger the function based on the update event or update the status using a function. User wants the function to only run when the status is updated to 'approved'. They are advised to create a duplicate collection to hold the last version of the document and trigger the function on update of the document in the original collection. They can then fetch the document from the other collection, compare, and update the document in the other collection. User is asked about their use case.
Drake
6 Jan, 2024, 21:24

What's your use case?

jesus
6 Jan, 2024, 21:28

I want the function to check if this specific attribute had an update and then procceed to create another document based on the previous document to a collection that is read only.

Drake
6 Jan, 2024, 21:36

I would create a duplicate collection that holds the last version of the document. Trigger the function on update of document in original collection and:

  1. Fetch document from other collection
  2. Compare
  3. Make sure to update the document in the other collection
jesus
6 Jan, 2024, 21:45

There is an attribute that have three stages (waiting for approval, approved, denied). I want if the document attribute called status got updated to (approved), the function should executes grabbing some data from the document and creates a final document in another collection.

jesus
6 Jan, 2024, 21:46

All of that in the server side I don't want to make it run manually from the client side.

jesus
6 Jan, 2024, 21:49

Can you help me figure it out 😫 if you have a better solution.

jesus
6 Jan, 2024, 21:51

I want this thing to only happen when the status is updated to (approved)

Drake
6 Jan, 2024, 22:06

I just told you how 🧐

jesus
6 Jan, 2024, 22:09

Yes, But i have to make it run on every update, is it possible to make it run on specific status on the status attribute.

jesus
6 Jan, 2024, 22:09

Or do I have to run manually in the client side.?

Drake
6 Jan, 2024, 22:13

Yes, function triggers on every document update in the collection

jesus
6 Jan, 2024, 22:16

Then if i want to create the final document when the status changes to (approved), i have to run the function manually on the client side and give it the required variables.

jesus
6 Jan, 2024, 22:16

Yes or no ?

jesus
6 Jan, 2024, 22:19

Because if i make the event on update, the function would trigger on (waiting for approval) then would run on (approved) another time because all the stages count as an update

Drake
6 Jan, 2024, 22:34

Yes, but it can just not create that final document

Drake
6 Jan, 2024, 22:35

Alternatively, you can update the status using a function instead of updateDocument() client-side

jesus
6 Jan, 2024, 22:41

I can make a manual excution for the function after the client side changes the document status to (approved) and send the document id to the function when executing so I can pull the data that i need to create the final document.

jesus
6 Jan, 2024, 22:42

I never thought of that😁

Drake
6 Jan, 2024, 23:09

Uh I was suggesting to trigger the function based on the update event

jesus
6 Jan, 2024, 23:10
jesus
6 Jan, 2024, 23:10

Thanks i figured it out

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