Backend script note issues #2151
-
I'm running Trilium v0.47.7. I'm trying to create a backend script that will fire when a note is created. The workflow I'm looking to do is: The problem I'm running into is that my JS backend doesn't want to fire. My initial tests have tried: and neither works. If I attempt to run the script with ctrl-enter, the first (console.log) does nothing but reports it ran, the second (api.showMessage) returns an error "Error when calling POST script/run/...." I've even tried changing this to fire similar to the task manager template and on runOnAttributeChange, but still nothing happens. I feel like I'm missing something, but not sure what. (edit - fixed a typo) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Solved this myself. Apparently runOnChildNoteCreation and runOnNoteCreation do not execute from a template (and api.showMessage is not an actual method; but api.log is which worked). I solved this by setting the ~runOnNoteCreation relationship on the parent note and not the template. I now have my backend script up and running and working perfectly. |
Beta Was this translation helpful? Give feedback.
Solved this myself. Apparently runOnChildNoteCreation and runOnNoteCreation do not execute from a template (and api.showMessage is not an actual method; but api.log is which worked).
I solved this by setting the ~runOnNoteCreation relationship on the parent note and not the template.
I also found that api.originEntity.getNote() (as referred to in other examples on these discussions) is no good. originEntity is itself a note and .getNote() is not a real method.
I now have my backend script up and running and working perfectly.