Help with script please


#1

In the following script, I would like to assign current draft’s contents as the “event.title”. Your help is greatly appreciated.

var calendar = Calendar.findOrCreate(“Activities”);
var event = calendar.createEvent();
event.title = “Dinner Party”;
event.notes = “Bring side dish.”;
event.startDate = Date.parse(“7pm next friday”);
event.endDate = Date.parse(“10pm next friday”);
event.isAllDay = false;
if (!event.update()) {
console.log(event.lastError);
}


#2

To literally set the full content of the draft as the title, you would use:

event.title = draft.content;

I might recommend you take it a step further, and use template tags like:

event.title = draft.processTemplate("[[title]]");
event.notes = draft.processTemplate("[[body]]");

This would be equivalent to using those tags in a step with templates, and assign the first line of the draft as the title, and the remaining text of the draft as the notes.

Hope this helps!


#3

Definitely helps Thanks v much !