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

Keyboard macros or custom scripts

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

Postby Mr.Dandy » Thu Jul 18, 2013 12:07 pm

Hello forum,

I try to pass some text to HelloWorld javascript.
Here my Basic code:
Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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.10 - Windows 10
User avatar
Mr.Dandy
 
Posts: 346
Joined: Tue Dec 11, 2012 4:22 pm

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

Postby hanya » Thu Jul 18, 2013 12:47 pm

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
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

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

Postby Mr.Dandy » Thu Jul 18, 2013 2:38 pm

D'oh!

Thanks hanya, you save my day.
User avatar
Mr.Dandy
 
Posts: 346
Joined: Tue Dec 11, 2012 4:22 pm

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

Postby atfrase » Fri Feb 12, 2021 12:41 am

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.
OpenOffice 4.1.8 on Linux Mint 20.1
atfrase
 
Posts: 1
Joined: Fri Feb 12, 2021 12:38 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 5 guests