Setting current date as calendar event name

Hi, I am trying to do something simple, I think. I want to create a new calendar entry where the title is the current date (2022-12-16) and the description / notes are what are in the current draft. However, I get an error, unexpected token %. Any thoughts on how to fix?

var cal = Calendar.find(“Life Log”);
var event = cal.createEvent();

var title = [[date|%Y-%m-%d]];
event.title = title;
event.notes = ‘From Drafts App’ + ‘\n’ + draft.processTemplate(“[[body]]”);;
event.startDate = draft.createdAt;
event.endDate = draft.createdAt;
event.location = draft.createdLatitude + ‘,’ + draft.createdLongitude;
event.isAllDay = true;

if (!event.update()) {
console.log(event.lastError);
}

That would be referring to this line:

var title = [[date|%Y-%m-%d]];

Which is not valid. It’s a valid Drafts tag, but in JavaScript, without anything around it, it would be trying to make that an array a failing. You need:

var title = draft.processTemplate(“[[date|%Y-%m-%d]]”);
1 Like

Thanks so much! I should have realized I need the draft.processTemplate function since I am using it to get the body of the draft!