How to call Object Script from javascript with a return value

178 views
Skip to first unread message

CmdrSpock

unread,
Sep 30, 2009, 9:52:05 AM9/30/09
to InterSystems: Zen Community
I have a user input form and I have a command button that the user
would push to locate the next available opening. I have a classmethod
which runs an SQL query to locate the next available opening and
returns it. However, I am calling a javascript function with the
command button, because I need to re-enable (disable=false) certain
controls on the page also. Or would it be easier to call the
javascript, to re-enable the controls, from the object script
function.

Here is my code;
<button caption=" New " onclick="getNextSocket();" />

Method getNextSocket() [ Language = javascript ]
{
// call to an ObjectScript routine that
// will return the next available socket number.
// If there are no more sockets available, popup a message.
var newSocket=zenPage.NextSocket()
// add code to popup a message if there are no more sockets
var tb=this.getComponentById('txtSocket');
tb.setProperty('value',x);
// only enable the radioset until the user makes a choice.
var comp=this.getComponentById('rsAppType');
comp.setProperty('disabled',false);

return;
}

/// This method will return the next available socket for assignment
ClassMethod NextSocket() [ Private ]
{
;Generate a random number for now, between 13000 and 18000
Quit nextSocket=$R(5000)+13000
// call class method to get an available socket
;##class(IPSockets.Sockets).GetNextSocket()
}

Neerav Verma

unread,
Sep 30, 2009, 10:01:49 AM9/30/09
to intersys...@googlegroups.com
Your approach should work fine.
Only thing I could note is that your method is missing and you have a statement after you Quit

As %String [ ZenMethod ]   .



Thank You,

Neerav Verma
http://www.linkedin.com/in/vneerav
------------------------------------------------------
Stephen Leacock  - "I detest life-insurance agents: they always argue that I shall some day die, which is not so."

CmdrSpock

unread,
Oct 7, 2009, 12:28:01 PM10/7/09
to InterSystems: Zen Community
It does not work, it produces an error:

ZEN EXCEPTION
http://127.0.0.1:8972/csp/ips/IPSockets.ZEN.SocketAssignment.cls

A JavaScript exception was caught in function function
zenInvokeCallbackMethod
TypeError: Object doesn’t support this property or method
------------------------------------------
Error invoking callback code.
Code: “zenPage.getNextSocket();”
Source: <button id=””>


------------------------------------------
Stack trace:
js:function zenExceptionHandler([object Error],[object Object],Error
invoking callback code.
C…)
js:function zenInvokeCallbackMethod(zenPage.getNextSocket();,[object
Object],onclick)
js:function zenFireEvent(10,zenPage.getNextSocket();,onclick,?)
js:function anonymous()


On Sep 30, 8:52 am, CmdrSpock <david.j.saund...@questdiagnostics.com>
wrote:
> I have a user input form and I have a command button that the user
> would push to locate the next available opening.  I have a classmethod
> which runs an SQL query to locate the next available opening and
> returns it.  However, I am calling ajavascriptfunction with the
> command button, because I need to re-enable (disable=false) certain
> controls on the page also.  Or would it be easier tocallthejavascript, to re-enable the controls, from the object script
> function.
>
> Here is my code;
> <button caption=" New " onclick="getNextSocket();" />
>
> MethodgetNextSocket() [ Language =javascript]
> {
>         //callto an ObjectScript routine that
>         // will return the next available socket number.
>         // If there are no more sockets available, popup a message.
>         var newSocket=zenPage.NextSocket()
>         // add code to popup a message if there are no more sockets
>         var tb=this.getComponentById('txtSocket');
>         tb.setProperty('value',x);
>         // only enable the radioset until the user makes a choice.
>         var comp=this.getComponentById('rsAppType');
>         comp.setProperty('disabled',false);
>
>         return;
>
> }
>
> /// Thismethodwill return the next available socket for assignment
> ClassMethod NextSocket() [ Private ]
> {
>          ;Generate a random number for now, between 13000 and 18000
>          Quit nextSocket=$R(5000)+13000
>         //callclassmethodto get an available socket
>          ;##class(IPSockets.Sockets).GetNextSocket()
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -

Neerav Verma

unread,
Oct 7, 2009, 12:59:22 PM10/7/09
to intersys...@googlegroups.com
Try onClick - the methods are case sensitive
What I do is I press space bar so auto complete shows me the list of methods and chances of errors like this are minimal

Thank You,

Neerav Verma
http://www.linkedin.com/in/vneerav
------------------------------------------------------
Charles de Gaulle  - "The better I get to know men, the more I find myself loving dogs."

CmdrSpock

unread,
Oct 7, 2009, 2:29:14 PM10/7/09
to InterSystems: Zen Community
I did use space bar. Using onClick generates an error during
complication of the class.

On Oct 7, 11:59 am, Neerav Verma <vnee...@gmail.com> wrote:
> Try onClick - the methods are case sensitiveWhat I do is I press space bar
> so auto complete shows me the list of methods and chances of errors like
> this are minimal
>
> Thank You,
>
> Neerav Vermahttp://www.linkedin.com/in/vneerav
> ------------------------------------------------------
> Charles de Gaulle<http://www.brainyquote.com/quotes/authors/c/charles_de_gaulle.html>
> > > - Show quoted text -- Hide quoted text -

Neerav Verma

unread,
Oct 7, 2009, 3:05:34 PM10/7/09
to intersys...@googlegroups.com
This is a working example. Of course it is not as complicated but it does returns values back from ZenMethod so that means you can do everything you can in objectscript and quit with your desired value

NOTE : quit would need to be there for it to work

<button caption="New" onclick="zenPage.Method1()/>

Method Method1() [ Language = javascript ]
{
       alert('Method1')
       var msg zenPage.Method2('Neerav')
       alert(msg)
}
Method Method2(Name As %String) As %String [ ZenMethod ]
{
       quit "Hello "_Name
}


Thank You,

Neerav Verma
http://www.linkedin.com/in/vneerav
------------------------------------------------------
Charles de Gaulle  - "The better I get to know men, the more I find myself loving dogs."
Reply all
Reply to author
Forward
0 new messages