I’m quite new to scripting but wrote the following. It won’t even run so any feedback would be appreciated. Loving Drafts 5 so far!
var d = Draft.content();
var sub1 = '## Invited';
var ninv = d.search(sub1);
I’m quite new to scripting but wrote the following. It won’t even run so any feedback would be appreciated. Loving Drafts 5 so far!
var d = Draft.content();
var sub1 = '## Invited';
var ninv = d.search(sub1);
If you want to work with the current existing draft then Draft should be lowercase. You’d use capital D Draft with create() to make a new one. Welcome to the quirks of javascript.
Thanks for the tip. I just tried this. Still not running…
Try this…
var d = draft.content;
var sub1 = "## Invited";
var ninv = d.search(sub1);
if (ninv == -1)
{
alert("No occurrences of\n'" + sub1 + "'\nwere found.");
}
else
{
alert("First occurrence of\n'" + sub1 + "'\nis at character position " + ninv + ".");
}
Worked perfectly. Thanks!
Just to highlight the changes then…
I also changed the quotes but that was just for consistency with my other lines
Makes sense now. Thanks!