How Effectively Does This Workflow Operate in Slack?

This topic was automatically generated from Slack. You can find the original thread here.

I’m not sure how well this works in slack, but here are some screenshots fo the workflow as well. Thanks for anyone’s help in figuring this out!

Hi , I understand that you want to update all Google Tasks listed, but the workflow only update one task. This is because you only refer to one task on your Google Update Task action.

To update all tasks, you’ll need to add a code step instead. For this usecase, Pipedream has the @Pi bot that can help to write the code for you.

I have all my Google tasks in the variable steps.list_tasks.$return_value, tell me steps to add a Node.js code step to update all the tasks with Completed to true

To update all Google Tasks with Completed set to true, you can add a Node.js code step in your workflow. Here’s an example of how you can achieve this: 1. Add a new “Run Node Code” action from the Node app in your workflow. 2. Replace the default code with the following: export default defineComponent({ async run({ steps, $ }) { const tasks = steps.list_tasks.$return_value; const updatedTasks = []; for (const task of tasks) { // Update the task with Completed set to true task.completed = true; updatedTasks.push(task); } return updatedTasks; }, }); This code step will iterate through all the tasks in steps.list_tasks.$return_value, set the completed property to true, and return the updated tasks.

I have all my Google tasks in the variable steps.list_tasks.$return_value, tell me steps to add a Node.js code step to update all the tasks with Completed to true and update any due dates that have changed.

To update all Google Tasks with Completed set to true and update any due dates that have changed, you can add a Node.js code step in your workflow. Follow these steps: 1. Add a new “Run Node Code” action from the Node app in your workflow. 2. Replace the default code with the following: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps, $ }) { const tasks = steps.list_tasks.$return_value; const updatedTasks = []; for (const task of tasks) { // Update the task with Completed set to true task.status = "completed"; // Update the due date if it has changed // Replace "newDueDate" with the updated due date value const newDueDate = "2022-12-31T23:59:59.000Z"; // Example date if (task.due !== newDueDate) { task.due = newDueDate; } // Update the task using Google Tasks API const taskId = task.id; const taskListId = task.taskListId; const accessToken = this.google.$auth.oauth_access_token; await axios($, { method: "PUT", url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}`, headers: { Authorization: `Bearer ${accessToken}`, "Content-Type": "application/json", }, data: task, }); updatedTasks.push(task); } return updatedTasks; }, }); This code step will iterate through all the tasks in steps.list_tasks.$return_value, set the status property to completed, update the due date if it has changed, and then update the tasks using the Google Tasks API. Make sure to replace the example newDueDate value with the updated due date value you want to set.

How could I change the newDueDate value to a date that is set in my notion database?

To change the newDueDate value to a date from your Notion database, you’ll first need to retrieve the date value from the database. You can use the Notion API to fetch the data. Assuming you have the Notion database ID and the property name containing the date, you can follow these steps: 1. Add a new “Run Node Code” action from the Node app in your workflow. 2. Replace the default code with the following: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { notion: { type: "app", app: "notion", }, databaseId: { type: "string", label: "Notion Database ID", }, datePropertyName: { type: "string", label: "Date Property Name", }, }, async run({ steps, $ }) { // Fetch the first page of the Notion database const response = await axios($, { method: "POST", url: `https://api.notion.com/v1/databases/${this.databaseId}/query`, headers: { "Authorization": `Bearer ${this.notion.$auth.oauth_access_token}`, "Notion-Version": "2022-05-13", "Content-Type": "application/json", }, }); // Find the first row with a date value in the specified property const rowWithDate = response.results.find(row => row.properties[this.datePropertyName].date); // Extract the date value const newDueDate = rowWithDate ? rowWithDate.properties[this.datePropertyName].date.start : null; if (newDueDate) { // Update tasks with the newDueDate value // Add your task updating code here } else { console.log("No date value found in the specified property."); } }, }); Make sure to replace the databaseId and datePropertyName with the appropriate values from your Notion database. This code will fetch the first page of the Notion database, find the first row with a date value in the specified property, and set the newDueDate variable to that date. You can then use the newDueDate value in your task updating code.

I have all my Google tasks in the variable steps.list_tasks.$return_value, tell me steps to add a Node.js code step to update all the tasks which have an updated “steps.trigger.event.properties.Due.date.start” from a notion trigger than what is in the google tasks variable steps.list_tasks.$return_value.

I have all my Google tasks in the variable steps.list_tasks.$return_value, tell me steps to add a Node.js code step to update all the tasks which have an updated “steps.trigger.event.properties.Due.date.start” from a notion trigger than what is in the google tasks variable steps.list_tasks.$return_value.

To update all the tasks in the steps.list_tasks.$return_value with the updated steps.trigger.event.properties.Due.date.start from a Notion trigger, you can follow these steps: 1. Add a new “Run Node Code” action from the Node app in your workflow. 2. Replace the default code with the following: export default defineComponent({ async run({ steps, $ }) { const notionDueDate = steps.trigger.event.properties.Due.date.start; const tasks = steps.list_tasks.$return_value; for (const task of tasks) { const taskDueDate = task.dueDate; // Replace 'dueDate' with the correct property name for the due date in the Google Tasks object if (new Date(notionDueDate) > new Date(taskDueDate)) { // Update the task with the new due date from Notion // Add your Google Tasks update code here, using the task ID and the new due date (notionDueDate) } } }, }); Make sure to replace dueDate in the task.dueDate line with the correct property name for the due date in the Google Tasks object. In the if statement, add your Google Tasks update code to update the task with the new due date from Notion. This code will loop through all the tasks in steps.list_tasks.$return_value and compare their due dates with the updated due date from the Notion trigger. If the Notion due date is greater than the task’s due date, it will update the task with the new due date.

This is what I have so far:

export default defineComponent({
async run({ steps, $ }) {
const notionDueDate = steps.trigger.event.properties.Due.date.start;
const tasks = steps.list_tasks.$return_value;

**for** (**const** task **of** tasks) {
  **const** taskDueDate = task.steps.list_tasks.$return_value.due

  **if** (**new** Date(notionDueDate) > **new** Date(taskDueDate)) {
    _// Update the task with the new due date from Notion_
    _// Add your Google Tasks update code here, using the task ID and the new due date (notionDueDate)_
  }
}

},
});

How do I get the task ID for the code?

It seems like you’re trying to access the task ID from the Google Tasks API response. In your code, you have a loop iterating through the tasks. To access the task ID, you can use task.id (assuming the Google Tasks API returns the task ID in the id property). Here’s the updated code: export default defineComponent({ async run({ steps, $ }) { const notionDueDate = steps.trigger.event.properties.Due.date.start; const tasks = steps.list_tasks.$return_value; for (const task of tasks) { const taskDueDate = task.due; // Replace 'due' with the correct property name for the due date in the Google Tasks object const taskId = task.id; // Access the task ID if (new Date(notionDueDate) > new Date(taskDueDate)) { // Update the task with the new due date from Notion // Add your Google Tasks update code here, using the taskId and the new due date (notionDueDate) } } }, }); Make sure to replace ‘due’ in the task.due line with the correct property name for the due date in the Google Tasks object. Now you can use taskId in your Google Tasks update code to update the task with the new due date from Notion.

How would I add a google tasks update code to the code you just listed?