MilkScript

Automate tasks with MilkScript.

menu

SmartList

Represents a Smart List. Smart Lists are special lists that are created based on criteria that you define, and are automatically updated as your tasks change.


delete()

Deletes the Smart List. No tasks are affected.

Return value

undefined

Example

// Deletes "Urgent" Smart List.
const urgentSmartList = rtm.getSmartLists()
  .find(smartList => smartList.getName() === 'Urgent');

if (urgentSmartList != null) {
  urgentSmartList.delete();

  console.log('Deleted "Urgent" Smart List.');
} else {
  console.log('"Urgent" Smart List not found.');
}

getCreatedDate()

Gets the date the Smart List was created.

Return value

Date

Example

// Outputs all Smart Lists and their created dates.
rtm.getSmartLists().forEach(smartList =>
  console.log("%s - %s", smartList.getName(), smartList.getCreatedDate()));

getFilter()

Gets the search criteria of the Smart List.

Return value

The search criteria of the SmartList.

Example

// Outputs all Smart Lists and their search criteria.
rtm.getSmartLists().forEach(smartList =>
  console.log("%s - %s", smartList.getName(), smartList.getFilter()));

getId()

Gets the ID of the Smart List.

Return value

string


getModifiedDate()

Gets the date the Smart List was last modified.

Return value

Date

Example

// Outputs all Smart Lists and their modified dates.
rtm.getSmartLists().forEach(smartList =>
  console.log("%s - %s", smartList.getName(), smartList.getModifiedDate()));

getName()

Gets the name of the Smart List.

Return value

The name of the SmartList.

Example

// Outputs all SmartLists
rtm.getSmartLists().forEach(smartList => console.log(smartList.getName()));

Gets a permalink for this Smart List.

Return value

String

Example

// Outputs all Smart Lists and their permalinks.
rtm.getSmartLists().forEach(smartList =>
  console.log("%s - %s", smartList.getName(), smartList.getPermalink()));

getTasks(filter)

Gets all tasks in this Smart List.

Parameters

filterOptional

If specified, only tasks matching the given criteria are returned.

Return value

The list of Tasks in this Smart List.

Example

// Outputs the number of incomplete tasks in your "Today at Work" Smart List.
const todayAtWork = rtm.getSmartLists()
  .find(smartList => smartList.getName() === 'Today at Work');

if (todayAtWork != null) {
  console.log('Incomplete tasks in your "%s" Smart List: %d',
    todayAtWork.getName(), todayAtWork.getTasks('status:incomplete').length);
} else {
  console.log('"Today at Work" Smart List not found.');
}

isFavorite()

Determines whether the Smart List is marked as a favorite.

Return value

true if the Smart List is marked as a favorite, false otherwise.

Example

// Outputs all favorite Smart Lists.
rtm.getSmartLists().forEach(smartList => {
  if (smartList.isFavorite()) {
    console.log(smartList.getName());
  }
});

setFavorite(favorite)

Sets whether the Smart List is marked as a favorite.

Parameters

favorite

true to mark the Smart List as a favorite, false otherwise.

Return value

The updated SmartList.

Example

// Favorites "Due Never" Smart List.
const dueNever = rtm.getSmartLists()
  .find(smartList => smartList.getName() === 'Due Never');

if (dueNever != null) {
  dueNever.setFavorite(true);

  console.log('Marked "%s" Smart List as a favorite.', dueNever.getName());
} else {
  console.log('"Due Never" Smart List not found.');
}

setFilter(filter)

Sets the search criteria of the Smart List.

Parameters

filter

The search criteria to use.

Return value

The updated SmartList.

Example

// Sets search criteria of "High Priority" Smart List to `Medium`.
const highPriority = rtm.getSmartLists()
  .find(smartList => smartList.getName() === 'High Priority');

if (highPriority != null) {
  highPriority.setFilter('priority:2');

  console.log('Updated search criteria of "%s" Smart List.',
    highPriority.getName());
} else {
  console.log('"High Priority" Smart List not found.');
}

setName(name)

Sets the Smart List name.

Parameters

name

The new name of the Smart List. Cannot be empty or contain only whitespace.

Return value

The renamed SmartList.

Example

// Renames "Urgent" Smart List to "URGENT!!!".
const urgent = rtm.getSmartLists()
  .find(smartList => smartList.getName() === 'Urgent');

if (urgent != null) {
  urgent.setName('URGENT!!!');

  console.log('Renamed "Urgent" Smart List to "%s".', urgent.getName());
} else {
  console.log('"Urgent" Smart List not found.');
}