Update Derivative field in Table 1 when column in Table 2 updated? #1276
-
Hi, New to Rowy so please bear with me... I'm doing some work with chatGPT but I don't want to hard code my prompts into the code for my derivative columns in Table 1 because takes to long to deploy every time I want to tweak the prompts. So I created a prompts table that stores the prompts. I've got that all working. Now only question is what is the best way to force the derivative column in Table 1 to update anytime the prompts in table 2 change. The prompts table does contain a column named "For Column" which contains string of table and column to be updated (i.e Table 1/columnName). If someone could provide the code and best way to do this... (extension I assume?) that would be much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @teddygarcia, we have a specific video tutorial that covers precisely what you're looking for. The attached video provides a step-by-step demonstration of how to synchronize changes between two tables. You'll need to create a Task Extension with the following script to implement this. Set the trigger event to const extensionBody: TaskBody = async({row, db, change, ref, logging}) => {
logging.log("extensionBody started");
if (change.after.exists) {
const previousCountryName = change.before.get("countryName");
const newCountryName = change.after.get("countryName");
// Update the corresponding cities with the new country name
const citiesSnapshot = await db.collection("cities")
.get();
const batch = db.batch();
citiesSnapshot.forEach(cityDoc => {
const cityRef = cityDoc.ref;
const cityData = cityDoc.data();
if (cityData.countryName === previousCountryName) {
batch.update(cityRef, { countryName: newCountryName });
}
});
await batch.commit();
logging.log("Updated cities with new country name");
}
} When a change event occurs and the "countryName" field is updated in the original table, it retrieves the corresponding cities from the "cities" collection and updates their "countryName" with the new value. Automating.Changes.mp4 |
Beta Was this translation helpful? Give feedback.
Hey @teddygarcia, we have a specific video tutorial that covers precisely what you're looking for. The attached video provides a step-by-step demonstration of how to synchronize changes between two tables.
You'll need to create a Task Extension with the following script to implement this. Set the trigger event to
Update
. Here's the code: