Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: Calling VFP procedures in Javascript

  1. #21
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,183
    Blog Entries
    22
    Where is tsearch declared exactly. You can test all this interactively in the JavaScript console. Just type tsearch.

    I don't agree with you. You are calling server side business procedures. It makes more sense to have them self contained. I can only recommend to you what to do. It's up to you.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  2. #22
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,183
    Blog Entries
    22
    I would suggest you read the release notes for v2.0 in particular the mention of server_functions. This functionality is coming into all apps to provide remote procedure calls to server side JavaScript functions and Lianja/vfp functions.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  3. #23
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658
    Hi Hank,

    I didn't find example_webapp3 all that helpful right now since it only passes variables to a message box and I didn't see anything that was escaped.
    I've been using example_registrationform as a guideline.

    Barry,

    I have the following just above the code that populates tsearch.
    Code:
    var tsearch = "";
    In the web browser, the following is reported:
    Uncaught ReferenceError: tsearch is not defined
    I'm assuming tsearch has been removed after it was used (also why I can't test in the javascript console tab).

    Using a breakpoint in the Sources tab of the web inspector (web app view), tsearch shows it has the correct value.

    Thanks Barry. I will look at the release notes.

    Cory

  4. #24
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,183
    Blog Entries
    22
    Please familiarize with JavaScript variable scope by googling "javascript variable scope".

    Lianja.evaluate() needs to be able to access the variable based on where it is declared.

    Write your own JavaScript function and experiment with trying to access variables outside of it.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  5. #25
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658
    Hi Barry,

    I'm pretty sure it is not a scoping issue since the variable is only local and is not called from anywhere else.
    The variable is used to pass its value to a procedure as a parameter.

    I believe I have discovered what the issue is.
    Instead of passing the value from the variable, the text 'tsearch' was being passed to the procedure.
    Code:
    //This wasn't working:
    var result = Lianja.evaluate('lib_webtest("get_brnum(\'{tsearch}\')")');
    
    // I was able to get it working by splitting everything into smaller sections.
    var brnumcall = "get_brnum('" + tsearch + "')";
    var libwebtest = 'lib_webtest("' + brnumcall + '")';
    var result = Lianja.evaluate(libwebtest);
    Could this have been handled in a better way?

    Cory

  6. #26
    Lianja Team yvonne.milne's Avatar
    Join Date
    Feb 2012
    Location
    Berkshire, UK
    Posts
    1,842
    Hi Cory,

    I don't want to convolute this further, especially if you have something working, but I would put a check in to test whether the code is running on the desktop or live in the Web Client and just use the {} macro in the Web Client.

    This is being called from a commandbutton click. I'm passing the txtsearch.text directly. The [] can be used as string delimiters 'in dev' as this is handled by the local Lianja/VFP scripting.

    Code:
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'click' event
    function page1_section1_field2_click()
    {
    	if (typeof LianjaAppBuilder === 'object')
    	// in dev
    	{
    	var result = Lianja.evaluate('lib_webtest("get_brnum(['+txtsearch.text+'])")');
    	}
    	else
    	// in live web/cloud
    	{
    	var result = Lianja.evaluate('lib_webtest("get_brnum(\'{txtsearch.text}\')")');
    	}
    
    	Lianja.writeLog(result);
    };
    In my original post about passing parameters into the library prg, when I mentioned PCOUNT(), I envisaged passing the parameters in individually to the library, rather than including them as a single parameter.

    For example, if this is my procedure library, lib_webtest.prg:

    Code:
    proc get_brnum
    parameters ptext
    return ptext + " was passed"
    endproc
    
    parameters funcname, para1
    do case
    	case pcount() = 1
    		return &funcname()
    	case pcount() = 2
    		return &funcname(para1)
    endcase
    I can pass 2 parameters to lib_webtest and it will treat the 2nd as a parameter to the function name in the 1st. Additional parameters can be added and handled with further PCOUNT() cases.

    So my button click code becomes:

    Code:
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'click' event
    function page1_section1_field1_click()
    {
    	if (typeof LianjaAppBuilder === 'object')
    	{
    	var result = Lianja.evaluate('lib_webtest("get_brnum","' + txtsearch.text + '")');
    	}
    	else
    	{
    	var result = Lianja.evaluate('lib_webtest("get_brnum","{txtsearch.text}")');
    	}
    
    	Lianja.writeLog(result);
    };
    and is probably more readable.

    Regards,

    Yvonne

  7. #27
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658
    Hi Yvonne,

    Thank you for the additional examples and explanation.
    That provides me a few other options that I can test with.

    I had originally set my procedure slightly differently by using the parameters inside the parentheses.

    Code:
    proc get_brnum(cclnum)
       nbrnum = 0
       ...
       return nbrnum
    endproc
    Cory

  8. #28
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    7,183
    Blog Entries
    22
    Hi Cory,

    If there is a need I do listen and always consider a better way of doing things if things look too complex and convoluted.

    In v2.0 I have therefore implemented the ability to call server side procedures that are contained in libraries as follows.

    // Client side JavaScript (notice the :: preceding myfunc()
    Code:
    var result = Lianja.evaluate("mylib::myfunc()");
    // Server side Lianja/VFP in mylib.prg
    Code:
    proc myfunc()
        return "hello world"
    endproc
    I have also mentioned in an earlier post that we will be providing a way to register server side functions in the Web/mobile client so that they can be called as if they were JavaScript client side functions.

    So for example you will be able to just do this in your client code.

    // Client side JavaScript
    Code:
    var result = myfunc();
    And myfunc() will be executed on the server. I will provide details of this prior to releasing v2.0.
    Last edited by barrymavin; 2015-07-09 at 13:51.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  9. #29
    Senior Member
    Join Date
    Jul 2013
    Location
    Ontario, Canada
    Posts
    658
    Hi Barry,

    Thank you for providing feedback on items you are working on that will make things easier.
    All of these hints, tips and tricks are helping me to view things from a different perspective that will hopefully improve my coding techniques.

    Cory

  10. #30
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    2,186
    Very nice!

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us