MilkScript Error Help
Hey there, I was wondering if you guys could help me fix a bug in my milkscript. I want it to create a new list, that will go ahead and grab all the tasks that have the earliest possible due date. And then add those tasks to the list. I make it check for existence and call list.delete() but for some reason it says there is an existing list already. Would you mind helping me find why line 28 is throwing an error? thanks
```js
// getting earliest due date from all tasks
const tasks = rtm.getTasks();
var minDueDate = tasks[0].getDueDate;
tasks.forEach(function(task) {
if (task.getDueDate() < minDueDate)
minDueDate = task.getDueDate();
});
// Setup "Earliest Due Tasks" list if exists
const urgentSmartList = rtm.getLists().find(list => list.getName() === 'Earliest Due Tasks');
// first making sure we keep the tasks from prev list leftover. Moving them bacc to the inbox
if (urgentSmartList != null) {
console.log('Moving %s tasks over to the inbox from the prev early list', urgentSmartList.getTasks.length);
urgentSmartList.getTasks().forEach(function(task) {
const inbox = rtm.getInbox();
task.setList(inbox);
});
}
// and now we fully delete list if exists. can clean this code to not check exists twice but whatever.
if (urgentSmartList != null) {
urgentSmartList.delete();
console.log('Deleted "Earliest Due Tasks" list.');
} else {console.log('"Earliest Due Tasks" list not found.');}
// adds a new list named "Earliest Due Tasks".
const earliestDueTasksList = rtm.addList('Earliest Due Tasks');
console.log('Added the list "%s".', earliestDueTasksList.getName());
// getting all tasks with the earliest due date and adds them to new list
var earliestDueTasks = tasks.filter( function(task) { return task.getDueDate() === minDueDate; });
earliestDueTasks.forEach(function(task) {
// move tasks to the new list from our inbox
task.setList(earliestDueTasksList);
});
```
```js
// getting earliest due date from all tasks
const tasks = rtm.getTasks();
var minDueDate = tasks[0].getDueDate;
tasks.forEach(function(task) {
if (task.getDueDate() < minDueDate)
minDueDate = task.getDueDate();
});
// Setup "Earliest Due Tasks" list if exists
const urgentSmartList = rtm.getLists().find(list => list.getName() === 'Earliest Due Tasks');
// first making sure we keep the tasks from prev list leftover. Moving them bacc to the inbox
if (urgentSmartList != null) {
console.log('Moving %s tasks over to the inbox from the prev early list', urgentSmartList.getTasks.length);
urgentSmartList.getTasks().forEach(function(task) {
const inbox = rtm.getInbox();
task.setList(inbox);
});
}
// and now we fully delete list if exists. can clean this code to not check exists twice but whatever.
if (urgentSmartList != null) {
urgentSmartList.delete();
console.log('Deleted "Earliest Due Tasks" list.');
} else {console.log('"Earliest Due Tasks" list not found.');}
// adds a new list named "Earliest Due Tasks".
const earliestDueTasksList = rtm.addList('Earliest Due Tasks');
console.log('Added the list "%s".', earliestDueTasksList.getName());
// getting all tasks with the earliest due date and adds them to new list
var earliestDueTasks = tasks.filter( function(task) { return task.getDueDate() === minDueDate; });
earliestDueTasks.forEach(function(task) {
// move tasks to the new list from our inbox
task.setList(earliestDueTasksList);
});
```
andrewski (Remember The Milk) says:
Hi milkymommy101,
Thanks for getting in touch. We see you emailed also and we'll get in touch there as it's a bit easier to format things! 😅
Thanks for getting in touch. We see you emailed also and we'll get in touch there as it's a bit easier to format things! 😅