The title of the step is “list_tasks”
Thank you for confirming the step name. Let’s add a “Run Node.js code” step right after the “list_tasks” step and modify the code like this: async run({ steps }) { const notionURL = steps.trigger.event.url; const existingTasks = steps.list_tasks.tasks.filter(task => task.notes === notionURL); this.filteredTasks = existingTasks; } Make sure to replace steps.trigger.event.url with the actual variable that holds the Notion URL from the trigger step. This code will filter the tasks based on the Notion URL and store the filtered tasks in this.filteredTasks. Now you can use this variable in the following steps to check if a task with the same Notion URL already exists and update the due date instead of creating a new task.
I’m not sure how to tell if the step is eturning an array of tasks in the tasks property.
To check if the “list_tasks” step is returning an array of tasks in the tasks property, you can add a “Run Node.js code” step right after the “list_tasks” step in your workflow. In this new step, add the following code: console.log(steps.list_tasks.tasks); This will log the output of the tasks property from the “list_tasks” step. Run your workflow and check the execution logs. If you see an array of tasks in the logs, then the step is returning the expected data.
I created the Node.js code step and copied this code: async run({ steps }) {
const notionURL = steps.trigger.event.url;
const existingTasks = {{steps.trigger.event.url}} (task => task.notes === notionURL);
this.filteredTasks = existingTasks;
}
But, I got this: Code Error
Unexpected token (1:9)
It looks like there’s a syntax issue in the code you provided. The correct code should be: async run({ steps }) { const notionURL = steps.trigger.event.url; const existingTasks = steps.list_tasks.tasks.filter(task => task.notes === notionURL); this.filteredTasks = existingTasks; } Make sure to replace list_tasks with the actual name of your “List Tasks” step in your workflow. Also, ensure that the “List Tasks” step is returning an array of tasks in the tasks property.
I’m trying to check if the list_tasks step is returning an array. I think it is. Here’s the path with 13 items: steps.node_1.$return_value
Great! If steps.node_1.$return_value contains an array of tasks, you can use it in your code. Here’s the modified code for filtering tasks based on the Notion URL: async run({ steps }) { const notionURL = steps.trigger.event.url; const existingTasks = steps.node_1.$return_value.filter(task => task.notes === notionURL); this.filteredTasks = existingTasks; } This code will filter the tasks based on the Notion URL and store the filtered tasks in this.filteredTasks. Now you can use this variable in the following steps to check if a task with the same Notion URL already exists and update the due date instead of creating a new task.
The list_tasks step itself has 17 items under this path: steps.list_tasks.$return_value
Great! Since the “list_tasks” step has an array of tasks under steps.list_tasks.$return_value, you can modify the code to filter tasks based on the Notion URL like this: async run({ steps }) { const notionURL = steps.trigger.event.url; const existingTasks = steps.list_tasks.$return_value.filter(task => task.notes === notionURL); this.filteredTasks = existingTasks; } This code will filter the tasks based on the Notion URL and store the filtered tasks in this.filteredTasks. Now you can use this variable in the following steps to check if a task with the same Notion URL already exists and update the due date instead of creating a new task.
I used this code, but I got an code error of an unexpected token.
import { axios } from “@pipedream/platform”;
export default defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
},
async run({ steps }) {
const notionURL = steps.trigger.event.url;
const existingTasks = steps.list_tasks.$return_value.filter(task => task.notes === notionURL);
this.filteredTasks = existingTasks;
}
It looks like there are some formatting issues in your code. Here’s the corrected version: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, }, async run({ steps }) { const notionURL = steps.trigger.event.url; const existingTasks = steps.list_tasks.$return_value.filter(task => task.notes === notionURL); this.filteredTasks = existingTasks; } });
This is the code I have for the “create_new_tasks” step. How should I update it for the previous step with the filtered notion url information?
import { axios } from “@pipedream/platform”;
export default defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
title: {
type: “string”,
label: “Notion Page Title”,
},
notionUrl: {
type: “string”,
label: “Notion Page URL”,
},
dueDate: {
type: “string”,
label: “Due Date”,
},
},
async run({ steps }) {
const notionPageUrl = this.notionUrl;
const tasksData = steps.list_tasks.$return_value
const tasks = tasksData && tasksData.tasks ? tasksData.tasks : [];
console.log(“Notion Page URL:“, notionPageUrl);
console.log(“Tasks:“, tasks);
const matchingTask = tasks.find(task => task.notes.includes(notionPageUrl));
**if** (!matchingTask) {
**const** title = **this**.title;
**const** dueDate = **this**.dueDate;
**const** url = “https://www.googleapis.com/tasks/v1/lists/Mk1hZng3dVdLeEJ6ZVZqUg/tasks”;
**const** body = {
title: title,
due: dueDate,
notes: notionPageUrl,
};
**await** axios(**this**, {
method: “POST”,
url: url,
headers: {
Authorization: `Bearer ${**this**.google_tasks.$auth.oauth_access_token}`,
“Content-Type”: “application/json”,
},
data: body,
});
}
},
});
Based on the filtered tasks from the previous step, you can update the “create_new_tasks” step to check if a task with the same Notion URL already exists. If it exists, update the task’s due date using the “Update Task” action from Google Tasks. If it doesn’t exist, create a new task as before. Here’s the updated code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ props: { google_tasks: { type: “app”, app: “google_tasks”, }, title: { type: “string”, label: “Notion Page Title”, }, notionUrl: { type: “string”, label: “Notion Page URL”, }, dueDate: { type: “string”, label: “Due Date”, }, }, async run({ steps }) { const existingTasks = steps.filtered_tasks.filteredTasks; const title = this.title; const dueDate = this.dueDate; if (existingTasks.length > 0) { // Update the existing task’s due date const taskId = existingTasks[0].id; const taskListId = existingTasks[0].taskListId; await axios(this, { method: “POST”, url: https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: { due: dueDate, }, }); } else { // Create a new task const url = “https://www.googleapis.com/tasks/v1/lists/@default/tasks”; const body = { title: title, due: dueDate, notes: this.notionUrl, }; await axios(this, { method: “POST”, url: url, headers: { Authorization: Bearer ${this.google_tasks.$auth.oauth_access_token}, “Content-Type”: “application/json”, }, data: body, }); } }, });
I got this error TypeError
Cannot read properties of undefined (reading ‘filteredTasks’)
I apologize for the confusion. It seems like the filteredTasks variable is not defined in the code you provided. To help you better, I need more information about the previous step where you filtered the tasks. Can you please provide the code for the previous step or explain how the tasks are being filtered? This will help me understand the issue and provide a solution.
This was the code you provided for the previous step where I filtered the task: import { axios } from “@pipedream/platform”;
export default defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
},
async run({ steps }) {
const notionURL = steps.trigger.event.url;
const existingTasks = steps.list_tasks.$return_value.filter(task => task.notes === notionURL);
this.filteredTasks = existingTasks;
}
});
Thank you for providing the code for the previous step. Based on this code, it seems that the filteredTasks variable is assigned to this.filteredTasks. To access this variable in the next step, you should use steps.<previous_step_name>.filteredTasks. Please replace <previous_step_name> with the actual name of the previous step where you filtered the tasks. Here’s the updated code for the “create_new_tasks” step: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google_tasks: { type: "app", app: "google_tasks", }, title: { type: "string", label: "Notion Page Title", }, notionUrl: { type: "string", label: "Notion Page URL", }, dueDate: { type: "string", label: "Due Date", }, }, async run({ steps }) { const existingTasks = steps.<previous_step_name>.filteredTasks; const title = this.title; const dueDate = this.dueDate; if (existingTasks.length > 0) { // Update the existing task's due date const taskId = existingTasks[0].id; const taskListId = existingTasks[0].taskListId; await axios(this, { method: "POST", url: `https://www.googleapis.com/tasks/v1/lists/${taskListId}/tasks/${taskId}`, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: { due: dueDate, }, }); } else { // Create a new task const url = "https://www.googleapis.com/tasks/v1/lists/@default/tasks"; const body = { title: title, due: dueDate, notes: this.notionUrl, }; await axios(this, { method: "POST", url: url, headers: { Authorization: `Bearer ${this.google_tasks.$auth.oauth_access_token}`, "Content-Type": "application/json", }, data: body, }); } }, }); Make sure to replace <previous_step_name> with the actual name of the previous step where you filtered the tasks.
I now have this error. TypeError
Cannot read properties of undefined (reading ‘length’)
DETAILS
at Object.run (file:///tmp/__pdg__/dist/code/16a4cdd84b79c5fb63d3bf8e194781ae4ad745b37dc85e61d9ddb75ce449231e/component.mjs:27:23)
at null.executeComponent (/var/task/launch_worker.js:229:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
Detailed/code mode
Google Tasks Account
Google Tasks LiveIntegrity
Notion Page Title
Look up Lencioni’s conflict exercises (For 2 hours type personal)
Notion Page URL
https://www.notion.so/Look-up-Lencioni-s-conflict-exercises-For-2-hours-type-personal-96b262325e6d438096dc19c34933de10
Due Date
2023-09-20T00:00:00+00:00
update_google_tasks_due_dates
CONFIGURE
CODE
RESULTS
query_database
CONFIGURE
update_google_tasks_completetion_status
CONFIGURE
CODE
RESULTS
google_tasks_updating_notes_duedates_completion
CONFIGURE
CODE
RESULTS
fetch_notion_tasks
CONFIGURE
CODE
RESULTS
I apologize for the confusion. It seems that the error is caused by trying to access the length property of an undefined variable. To help you better, I need to know the name of the previous step where you filtered the tasks. Please provide the name of that step, and I’ll help you update the code accordingly.