Time based field update with workflow
Good day,
Any smart people out there that can explain how I can do a workflow that will change based on a requirement?
I want to create a workflow that runs daily. Checking a field called "expiry date". If that field's expiry date is within 6 months, a record should be updated called "Expired" to "6 months" entry (it's a select field)
6 Replies
Hi @Dream, you need :
- a cron trigger that runs daily. It already exists
- a code action that will fetch all records using twenty api. It will loop over all records, and check the expiry date. Then you will use the twenty api again to update the expired field if needed
Available doc for the api is there https://twenty.com/developers/rest-api/core#/
Twenty.com
Open Source CRM
Soon we will have additional actions that will avoid writing code and talking to the api yourself :
- an action to search records easily
- an action to loop over a list of records
- the action to update a record already exists but since you want to check a list of records it won't work in your use case
Thanks @thomast, Feel free to look over the code and recommend changes, if you want. Not a necessity, as it works, and only needs to work as long as the new workflow features aren't released.
I ended up doing this, using a lot of CoPilot. I'm not a coder, just know some basics.
For anyone that might need this in the future. This finds all people in person tab, looks for "expiry" field. If date is more than 6 months away, marks a field as "active", less than 6 months marks as "6 months" and past the date marks as "expired"
Well done for getting this work 👌
Calling the api to fetch the people one by one will work, but it may take some time. You can fetch all people at once by doing:
And then only you start your loop.
I thought about this but I ran into an issue when trying find many, i’ll give your code a shot and see how I can change it.
Highly appreciated!
A bit off topic - I’m currently using some python scripts that scans a folder for CSV files, once 1 is added, it automatically imports the csv file into the database of people/companies.
Will there ever be a way I could do this using workflow?
At some point we'll propose app connections. You could link your google sheet or other softwares that manage csv. Then you'll be able to listen at csv creations as a trigger to your workflow