Describe the problem/error/question
Got error “No execution data available [line 3]” first, and found the situation when a new user has no enrolled course before, will have “No output data returned” from previous node HTTP Request2usercourses.
Then tried to modify the code as following, but got “Code doesn’t return items properly”, any suggestion for how to modify the code?
module.exports = async function(inputData) {
const { courseData } = inputData;
// Validate input data
if (!courseData) {
return {
items: [
{
json: {
message: "Error: Missing course data. Unable to process course prerequisite check.",
courseId: null,
categoryId: null,
requiresPreCourse: false
}
}
]
};
}
// Safely extract course details with fallbacks
const courseId = courseData.id || null;
const categoryId = courseData.categoryid || null;
// Define the pre-course requirement details
const preCourseCategory = 2;
const preCourseId = 10;
// Initialize output variables
let outputMessage;
let hasCompletedPreCourse = false;
// Validate categoryId before processing
if (categoryId === null) {
return {
items: [
{
json: {
message: "Error: Invalid category ID. Unable to determine course requirements.",
courseId,
categoryId,
requiresPreCourse: false
}
}
]
};
}
// Handle the case where userCourses is not provided (new user)
if (inputData.userCourses === undefined) {
outputMessage = `Please complete the pre-course (Course ID: ${preCourseId}) before taking this course.`;
hasCompletedPreCourse = false;
} else if (categoryId === 4) {
// Category 4 doesn't require a pre-course
outputMessage = "No pre-course is required for this course.";
} else if (categoryId === preCourseCategory) {
// Check if pre-course is completed for existing users
hasCompletedPreCourse = inputData.userCourses.some(course => course.id === preCourseId);
if (hasCompletedPreCourse) {
outputMessage = "You have already completed the required pre-course. You can proceed with the course.";
} else {
outputMessage = `Please complete the pre-course (Course ID: ${preCourseId}) before taking this course.`;
}
} else {
// No specific requirements for other categories
outputMessage = "No pre-course requirement for this course. You can proceed with the course.";
}
// Set the output data with a user-friendly message
return {
items: [
{
json: {
message: outputMessage,
courseId,
categoryId,
requiresPreCourse: categoryId === preCourseCategory && !hasCompletedPreCourse
}
}
]
};
};
What is the error message (if any)?
ExpressionError: No execution data available at Object.get (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/WorkflowDataProxy.js:300:31) at get () at VM2 Wrapper.get (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:452:11) at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:3:55 at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code:52:2 at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/bridge.js:490:11) at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/@n8n/vm2/lib/nodevm.js:497:23) at JavaScriptSandbox.runCodeAllItems (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox.js:50:45) at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Code/Code.node.js:130:40) at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:722:42) at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:704:66 at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:1134:20
Please share your workflow
Share the output returned by the last node
Information on your n8n setup
- **n8n version: 1.69.2
- **Database (default: SQLite): default
- **n8n EXECUTIONS_PROCESS setting (default: own, main): default
- **Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
- **Operating system: Windows