Using a variable in the [[line]] tag

I’m writing a javascript and I’m trying to use a loop to find the first blank line in a draft. To do that, I’m using the process.Template function. But instead of a fixed number or range, like [[line|3]], I’m trying to set a line number with a predefined variable called “TheLineNum”:

ThisLine = draft.processTemplate("[[line|TheLineNum]]");

When I do, this line does not seem to be working. The rest of the script seems to work when I replace TheLineNum with the actual number 3.

I’m trying to figure out a larger script that I want to write, piece by piece, but I’m stuck at this point, haha!

To answer your specific question, in Javascript, variables are not evaluated inside a literal string. You would need to construct the string to be the template for it to work, something like:

let line = draft.processTemplate(“[[line|” + lineNum + “]]”);

That said, I would recommend a different approach to find the blank line. Like:

// break draft into an array of lines
let lines = draft.content.split(“\n”);
// loop over lines to find a blank...
for (let ix = 0; ix < lines.length; ix++) {
  if (lines[ix].length == 0) { // this is a blank line!
    // do something? Not sure what.
  }
}

Greg - Thank you!!!

Actually, i was able to use both of these methods successfully. (Took me a hot minute because i didn’t realize the first line in the variable was 0, not 1, haha!)

Using my new script, i’m able to start in a draft with a list of questions, identify how many lines the first question is on, copy that question to the clipboard and the delete that question from the draft. Really excited this works.

One more question - I couldn’t find anything by searching this forum:

Now i want to do this from another draft. Be in a draft, launch the action which will jump to my specific draft with the list of questions, perform the action above and then jump back to my first draft and paste. I thought i could do it using URL steps, but I’m a little stuck. I jump to my draft via the specific UUID, but the Javascript step of the action is executed against the original draft, not the one I jumped to. Any advice?