zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
26.09k stars 1.78k forks source link

Change note title #4754

Closed RossMarks-Capgemini closed 1 month ago

RossMarks-Capgemini commented 1 month ago

I'm trying to change a notes title using the API.

Documentation is thin and confusing. So far I've managed:

console.log("New page created with ID:", createdNoteId);
this.changeNoteTitle(createdNoteId);

 async changeNoteTitle(taskNoteId) {
    const note = await api.getNote(taskNoteId);
      note.title = "page id: "+taskNoteId;
      console.log("changeNoteTitle func: "+note);      
  }

This does change the note's title however it doesn't change on the sidebar and isn't permanent (If I browse away and come back the old title returns) is there some way to save it or make it permanent? I feel like I'm missing something obvious?!

RossMarks-Capgemini commented 1 month ago

nevermind, solved it.. probably not the right way but it's working:

        console.log("New page created with ID:", createdNoteId);

          api.runOnBackend((createdNoteId) => {
              const note4 = api.getNote(createdNoteId);
              note4.title = "noteID: "+createdNoteId;
              note4.save();
          }, [createdNoteId]);