Replace selected text

What is wrong with this script? I am sure it is a total newbie mistake

var $content, cb;

$content = draft.content;

cb = app.getClipboard();



Try this:


So, there’s a few things “wrong” with your code. First, you don’t need to declare variables before assigning them content, and variables don’t need to (and arguably shouldn’t) start with a dollar sign in JavaScript.

The key error though is you are trying to do setSelectedText without using the Draft it’s attached to.

Hopefully my code works - it is untested though!

Just a couple of extra bits.

These days, JavaScript variables prefixed with dollar symbols tend to, purely by convention, be associated with variables available from libraries/frameworks, rather than mainline code.

If the functionality of this script is feature complete, then it can also be achieved with an arguably simpler action step.

1 Like

I get an error message that says draft.setSelectedTexti. Is not a function. Maybe I need to define a function first. Believe it or not I am an ABAP programmer but am just dipping my finger into JavaScript.

I changed it to editor.setSelectedText(…

And it worked.

Thanks for pointing me in the right direction. (After your reply another post made some more sense to me).

Thank you sylumer.! That works too. It will replace a selected text.

Whoops, sorry, this is what happens when you code without testing while half asleep!