I see, you want the updatedTasks array to be populated with tasks from Notion that have been marked as complete, and then update the corresponding Google Tasks accordingly. To achieve this, you’ll need to modify the code that retrieves tasks from Notion. You should have a step before this code that fetches the tasks from Notion and filters them based on their completion status. Assuming you have a step named fetch_notion_tasks that fetches tasks from Notion, you can filter the tasks like this: const notionTasks = steps.fetch_notion_tasks.data; const updatedTasks = notionTasks.filter(task => task.properties.done.checkbox === true); Then, replace the line const updatedTasks = steps.trigger.event.updatedTasks || []; with the code above. This will populate the updatedTasks array with tasks that are marked as complete in Notion. Make sure you have the appropriate step to fetch tasks from Notion and that the data structure matches the one used in the code snippet above. If you need help with fetching tasks from Notion, please let me know.
I used this code:
import { axios } from “@pipedream/platform”;
export default defineComponent({
props: {
google_tasks: {
type: “app”,
app: “google_tasks”,
},
},
async run({ steps }) {
const notionTasks = steps.query_database.data;
const updatedTasks = notionTasks.filter(task => task.properties.done.checkbox === true);
const tasksData = steps.list_tasks.data;
const tasks = tasksData && tasksData.tasks ? tasksData.tasks : [];
console.log(“Updated Tasks:“, updatedTasks);
console.log(“Google Tasks:“, tasks);
**for** (**const** taskToUpdate **of** updatedTasks) {
**const** notionUrl = taskToUpdate.notes;
**const** task = tasks.find((task) => task.notes === notionUrl);
console.log(“Task to update:“, taskToUpdate);
console.log(“Matching Google Task:“, task);
**if** (task) {
**const** taskId = task.id;
**const** isCompleted = steps.trigger.event.properties.done.checkbox;
console.log(“Is completed:“, isCompleted);
**const** url = `https://www.googleapis.com/tasks/v1/lists/@default/tasks/${taskId}`;
**const** body = {
status: isCompleted ? “completed” : “needsAction”,
};
**await** axios(**this**, {
method: “PUT”,
url: url,
headers: {
Authorization: `Bearer ${**this**.google_tasks.$auth.oauth_access_token}`,
“Content-Type”: “application/json”,
},
data: body,
});
}
}
},
});
But I got this error: TypeError
Cannot read properties of undefined (reading ‘filter’)
It looks like the error is caused by steps.query_database.data being undefined. To resolve this issue, please make sure that you have a step named query_database in your workflow that fetches tasks from Notion and outputs the data in the expected format. If you’re still having trouble, please provide more information about the query_database step, and I’ll be happy to help you further.
this is the name of the step: query_database
Thank you for providing the step name. Now, please replace steps.query_database.data with steps.query_database.$return_value in your code: ```
const notionTasks = steps.query_database.$return_value; const updatedTasks = notionTasks.filter(task => task.properties.done.checkbox === true);
When i changed that, I got this error: TypeError
notionTasks.filter is not a function
I apologize for the confusion. It seems that the notionTasks variable might not be an array, which is causing the error. To debug this issue, let’s log the notionTasks variable before filtering it. Please add a console.log(notionTasks) line before the filter operation: const notionTasks = steps.query_database.$return_value; console.log("Notion Tasks:", notionTasks); const updatedTasks = notionTasks.filter(task => task.properties.done.checkbox === true); After adding this line, run your workflow and check the logs to see the output of Notion Tasks. This will help us understand the structure of the data and identify the issue. Please share the output, and I’ll help you resolve the problem.
This is the result I got in the log.
It seems you didn’t provide the log output. To help you further, please share the output of the console.log("Notion Tasks:", notionTasks) line from your code. This will help us understand the structure of the data and identify the issue.
The log:
The log is too long for slack to let me paste. It’s all the properties of the database from notion.
I understand that the log is too long to paste here. In that case, let’s try to identify the structure of the data by adding a few more console.log statements to help us understand the data format. Please add these lines right after the console.log("Notion Tasks:", notionTasks); line: ```
console.log(“Notion Tasks Type:”, typeof notionTasks); console.log(“Notion Tasks Length:”, notionTasks.length); console.log(“Notion Tasks First Item:”, notionTasks[0]);
Here’s what I got: Notion Tasks First Item: undefined
Thank you for providing the log output. It seems that the first item in the notionTasks array is undefined. Let’s add another console.log statement to check the entire array: ```
console.log(“Notion Tasks Array:”, JSON.stringify(notionTasks, null, 2));
Here’s the rest of what I got: 9/19/2023, 1:00:58 PM
Notion Tasks Type: object
9/19/2023, 1:00:58 PM
Notion Tasks Length: undefined
9/19/2023, 1:00:58 PM
Notion Tasks First Item: undefined
Thank you for providing the additional log output. It seems that notionTasks is an object instead of an array, which is why the filter function is not working. To further investigate the issue, let’s log the object keys to understand its structure. Please add the following line after the console.log("Notion Tasks:", notionTasks); line: ```
console.log(“Notion Tasks Object Keys:”, Object.keys(notionTasks));
Here’s the response to that: Notion Tasks Object Keys: [
‘object’,
‘results’,
‘next_cursor’,
‘has_more’,
‘type’,
‘page_or_database’
]
Thank you for providing the object keys. It appears that the results key contains the data we need to filter. Let’s update the code to use notionTasks.results instead: const notionTasks = steps.query_database.$return_value; console.log("Notion Tasks:", notionTasks); const updatedTasks = notionTasks.results.filter(task => task.properties.done.checkbox === true); This should resolve the issue with the filter function. If you still encounter any problems, please let me know.
It seems like my workflow is having a couple of problems. I think my step that’s supposed to compare my list of google tasks to my list of notion tasks and create a new google task only if there isn’t already a google task with the notion url in it is actually just creating a new google task no matter what.
I’m sorry to hear that you’re having issues with your workflow. To help you resolve the problem, I’ll need to see the relevant part of your code that compares the Google Tasks and Notion Tasks, and creates a new Google Task if the condition is met. Please share the code snippet, and I’ll help you identify and fix the issue.