The problem is that my Javascript is not embedded in a Workflow. It is a web script interacting with a running workflow so I cannot do exactly the same thing that is possible when using Javascript directly within the workflow.