Draft.queryByTitle returning an array containing an empty object

Trying to write a script that creates a note with a specific title if it doesn’t already exist.

d = Draft.queryByTitle("Foo")[0]

alert(JSON.stringify(d));

alerts with the value{}

A draft exists with the title ‘Foo’ and I would expect that to be returned.

Is anyone else successfully using queryByTitle? This is using Drafts 25.0.12 on OSX.

Thanks

Out of interest does this give you anything?

Draft.queryByTitle("Foo").map(d => alert(d.content));

Then this.

alert(JSON.stringify(draft));

Thanks sylumer,

That works, obviously JSON.stringify does not do what I think it does :).

I think it probably does do what you think. But, I think it doesn’t always do what we would want because it does have some purposeful limitations.

But, we can usually coerce the result we’re after with something like this, for example.

alert(JSON.stringify(draft, ["createdAt", "modifiedAt", "createdLatitude", "createdLongitude", "modifiedLongitude", "modifiedLatitude", "content", "displayTitle", "isArchived", "isFlagged", "isTrashed", "languageGrammar", "lines", "permalink", "selectionLength", "selectionStart", "title", "uuid", "versions"]));
1 Like