Forums

Discuss all things Remember The Milk.

menu

MilkScript Error Help

milkymommy101 says:
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);
});
```
Posted at 3:27pm on June 9, 2023
milkymommy101 says:
I tested just the delete part and it seems to work

maybe there needs to be some polling or sleep functionality to wait to create new list until old one is "fully deleted"
Posted 10 months ago
milkymommy101 says:
it can't create a new list after deleting the old one with the same name
Posted 10 months ago
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! 😅
Posted 10 months ago
This topic has now been closed automatically due to a lack of responses in the past 90 days.