Adding prompt button result to text?

I have an action someone else wrote to append the current draft to my Logseq journal. I want to make this more useful by first prompting the user whether the text should be treated as plain text (in which case it will just be like before) or if it is a task, in which case it will append TODO or NOW or LATER to the beginning of the text before posting to Logseq.

I have been able to create a prompt that has four buttons: Text|TODO|NOW|LATER

However, I’m stuck at how to then pull the result into the next action. Here is what I have right now:

// evaluate the prompt entries
var q = '';
var qbutton = draft.getTag('prompt_button');

if( qbutton == "text" )
    { q += '' }    // leave blank
    { q += qbutton }  // pass along selected button

- {q} [[draft]]

What this currently does is appends the above script as text, rather than just the variable “q” + the draft contents. Any help would be appreciated!

You are not so far off…

After a prompt step is run, a new template tag will exist for the for the value of the button. In your example (and the default behavior), would be for that tag to be [[prompt_button]]. You can likely just use than in your “File” step to fill in the value without the need for scripting.

(The key in the prompt step determines the prefix for the tag - so if you have more than one prompt step, you could use prompt2 for the key and the tag would be [[prompt2_button]], and so on.)

If you do need to further construct a string in script from the prompt button, the way to get that value in a script would be:

let button = draft.processTemplate("[[prompt_button]]")

Hope this helps!

Wow. That was much easier than I thought!

So my action now is just:

- [[prompt_button]] [[draft]]

The only reason for scripting was to have the text be blank in certain situations, since there seems to be no way to have a blank prompt button? But I’ve handled that by turning the first prompt to a tag #qc (for quick capture) which can be useful for filtering.