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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

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

Post 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
Last edited by Mr.Dandy on Thu Jul 18, 2013 2:39 pm, edited 1 time in total.
OpenOffice 4.1.12 - Windows 10
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

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

Post by hanya »

Close the Rhino debugger, the arguments is empty it is opened.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

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

Post by Mr.Dandy »

D'oh!

Thanks hanya, you save my day.
atfrase
Posts: 7
Joined: Fri Feb 12, 2021 12:38 am

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

Post 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.
Post Reply