Note
Represents a task note.
delete()
Deletes the note.
Return value
undefined
Example
// Deletes all notes in "Top Secret" tasks.
const tasks = rtm.getTasks('name:"Bob\'s Top Secret Notes"');
tasks.forEach(task => {
task.getNotes().forEach(note => note.delete());
});
console.log('Deleted all notes in %d top secret task(s). Phew!', tasks.length);
getAuthor()
Gets the author of the note.
Return value
The User
who is the author of the note.
Example
// Outputs the author of the longest note.
const tasks = rtm.getTasks('hasNotes:true AND status:incomplete');
let longestNote = null;
tasks.forEach(task => {
task.getNotes().forEach(note => {
if (longestNote == null ||
note.getContent().length > longestNote.getContent().length) {
longestNote = note;
}
});
});
if (longestNote != null) {
console.log('"%s" is the author of the longest note (%d characters).',
longestNote.getAuthor().getUsername(), longestNote.getContent().length);
} else {
console.log('You have no tasks with notes.');
}
getContent()
Gets the content of the note.
Return value
The text content of the note.
Example
// Outputs the content of the oldest note.
const tasks = rtm.getTasks('hasNotes:true');
let oldestTask = null;
tasks.forEach(task => {
if (oldestTask == null ||
oldestTask.getCreatedDate().getTime() >
task.getCreatedDate().getTime()) {
oldestTask = task;
}
});
if (oldestTask != null) {
let oldestNote = null;
oldestTask.getNotes().forEach(note => {
if (oldestNote == null ||
note.getCreatedDate().getTime() <
oldestNote.getCreatedDate().getTime()) {
oldestNote = note;
}
});
console.log(
'---------------Your oldest note---------------\nDate: %s\n\n%s\n\n',
oldestNote.getCreatedDate(), oldestNote.getContent());
} else {
console.log('You have no tasks with notes.');
}
getCreatedDate()
Gets the date the note was created.
Return value
Example
// Outputs when your latest note was added.
const tasks = rtm.getTasks('hasNotes:true AND status:incomplete');
let latestNote = null;
tasks.forEach(task => {
task.getNotes().forEach(note => {
if (latestNote == null ||
note.getCreatedDate().getTime() >
latestNote.getCreatedDate().getTime()) {
latestNote = note;
}
});
});
if (latestNote != null) {
console.log('Your latest note was created on %s',
latestNote.getCreatedDate());
} else {
console.log('You have no tasks with notes.');
}
getId()
Gets the ID of the note.
Return value
string
getLastEditor()
Gets the user who last edited the note.
Return value
The User
who last edited the note, or null
if the note was never edited.
Example
// Outputs the list of users who edited notes today.
const now = new Date();
const tasks = rtm.getTasks('hasNotes:true AND updated:today"');
const editedNotes = [];
tasks.forEach(task => {
task.getNotes().forEach(note => {
if (note.getModifiedDate().getFullYear() === now.getFullYear() &&
note.getModifiedDate().getMonth() === now.getMonth() &&
note.getModifiedDate().getDate() === now.getDate()) {
editedNotes.push(note);
}
});
});
if (editedNotes.length === 0) {
console.log("No one edited notes today.");
} else {
editedNotes.sort((a, b) =>
a.getModifiedDate().getTime() - b.getModifiedDate().getTime());
editedNotes.forEach(note => console.log("%s - %s",
note.getModifiedDate(), note.getLastEditor().getUsername()));
}
getModifiedDate()
Gets the date the note was last modified.
Return value
Example
// Outputs the number of notes edited today.
const now = new Date();
const tasks = rtm.getTasks('hasNotes:true AND updated:today"');
let count = 0;
tasks.forEach(task => {
task.getNotes().forEach(note => {
if (note.getModifiedDate().getFullYear() === now.getFullYear() &&
note.getModifiedDate().getMonth() === now.getMonth() &&
note.getModifiedDate().getDate() === now.getDate()) {
++count;
}
});
});
console.log('You have edited %d note(s) today.', count);
setContent(content)
Sets the content of the note.
Parameters
content
The new content of the note. Cannot be empty or contain only whitespace.
Return value
The updated Note
.
Example
// Changes "bananas" in all notes to "BANANAS".
const tasks = rtm.getTasks('noteContains:bananas');
let count = 0;
tasks.forEach(task => {
task.getNotes().forEach(note => {
if (note.getContent().indexOf('bananas') >= 0) {
note.setContent(note.getContent().replaceAll('bananas', 'BANANAS'));
++count;
}
});
});
console.log("Updated %d note(s).", count);