Page 1 of 1

[Solved] [Basic] Unable to pass the argument to Javascript

Posted: Thu Jul 18, 2013 12:07 pm
by Mr.Dandy
Hello forum,

I try to pass some text to HelloWorld javascript.
Here my Basic code:

Code: Select all

Sub Main
	HelloJS
End Sub

Function HelloJS
	Dim oSP, oJS
	Dim param(0), s
	oSP = ThisComponent.getScriptProvider()
	oJS = oSP.getScript("vnd.sun.star.script:Library1.Hello.js?language=JavaScript&location=document")
	s = oJS.invoke(Array("I say hello"),Array(),Array())
	HelloJS = s
End Function
And my JS code:

Code: Select all

importClass(Packages.com.sun.star.uno.UnoRuntime);
importClass(Packages.com.sun.star.text.XTextDocument);
importClass(Packages.com.sun.star.text.XText);
importClass(Packages.com.sun.star.text.XTextRange);
importClass(Packages.com.sun.star.frame.XModel);

sSource = String(ARGUMENTS[0]) 

oDoc = UnoRuntime.queryInterface(XModel,XSCRIPTCONTEXT.getInvocationContext());
if ( !oDoc )
  oDoc = XSCRIPTCONTEXT.getDocument();
xTextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc);
xText = xTextDoc.getText();
xTextRange = xText.getEnd();
xTextRange.setString( sSource );
But "undefined" is written.

How can I get the text?

Thanks

Re: [Basic] Unable to pass the argument to Javascript

Posted: Thu Jul 18, 2013 12:47 pm
by hanya
Close the Rhino debugger, the arguments is empty it is opened.

Re: [Basic] Unable to pass the argument to Javascript

Posted: Thu Jul 18, 2013 2:38 pm
by Mr.Dandy
D'oh!

Thanks hanya, you save my day.

Re: [Solved] [Basic] Unable to pass the argument to Javascri

Posted: Fri Feb 12, 2021 12:41 am
by atfrase
Some kind of warning or notice about this would be really, really nice.

I just spent 8 hours banging my head against the wall wondering why ARGUMENTS was evidently defined, but not populated, and finally happened across just the right arcane invocation of search terms to find this random one-off comment on a 7 year old post explaining that simply having the debugger open silently makes the code not work.