Alpha Video Training
Results 1 to 12 of 12

Thread: Help needed parsing value from javascript to an xbasic function

  1. #1
    Banned
    Join Date
    Aug 2003
    Posts
    1,416

    Default Help needed parsing value from javascript to an xbasic function

    OK, so I want to parse a date value to an xbasic user defined function, which is not working as planned.

    Basically, the javascript has the following line that creates an xbasic string:

    Code:
    var xb = 'Function1('+nr1+',"'+name1+'",'+date1+','+interval+','+nr2+')';
    genericXbasicUIFromWorkingPreview(xb);
    However, when this is picked up by xbasic the function returns:
    ERROR: Variable type mismatch: attempt to pass data of type 'N' to argument 'eersteentingdatum ' is of type 'D'.
    Apparently, it sees the value date1 as a number.
    When I tried adding curly brackets to a value in the interactive window (xbasic), it passed correctly.
    Solution: adding curly brackets in the javascript that builds the string to pass to xbasic.

    I don't seem to be able to get THAT right.
    I tried almost everything (except what works ) but I can't get it right. I tried to escape the "{" by using "\" but obviously that did not work.
    Normally in javascript you could escape the curly bracket with another curly bracket (using 2) like: "{{" but that does not work either.

    So my hopes are with you guys. How do I get {22-02-2013} parsed to my xbasic function?

    Any help is highly appreciated.....

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Help needed parsing value from javascript to an xbasic function

    the javascript has the following line that creates an xbasic string:
    And what would a sample of that string look like?

    parse a date value to an xbasic user defined function
    How is the function defined?
    There can be only one.

  3. #3
    Banned
    Join Date
    Aug 2003
    Posts
    1,416

    Default Re: Help needed parsing value from javascript to an xbasic function

    Quote Originally Posted by Stan Mathews View Post
    And what would a sample of that string look like?
    Hi Stan, thanks for helping!
    What do you mean, the sample is in my first post in the code section? Or do I misunderstand you?

    This is the javascript that gets executed on the button onclick event:
    (I had this slightly reformatted because the fieldnames are in Dutch, most wouldn't understand them)

    Code:
    var rowNumber = {Grid.RowNumber};
    var aantalintervallen = {grid.Object}.getValue('G','AANTALINTERVALLEN',{Grid.RowNumber});
    var entingnaam = {grid.Object}.getValue('G','ENTINGNAAM',{Grid.RowNumber});
    var eersteentingdatum = {grid.Object}.getValue('G','EERSTEENTINGDATUM',{Grid.RowNumber});
    var interval = {grid.Object}.getValue('G','INTERVAL',{Grid.RowNumber});
    var volgnummer = {grid.Object}.getValue('G','VOLGNUMMER',{Grid.RowNumber});
    var xb = 'Function1('+aantalintervallen+',"'+entingnaam+'",'+eersteentingdatum','+interval+','+volgnummer+')';
    genericXbasicUIFromWorkingPreview(xb);
    The problem lies within the '+eersteentingdatum+' section of the javascript string. Although the field is a datefield, the javascript passes the value to the xbasic function as a number value.
    When I tried in the interactive window, just adding curly brackets to the value made it work. But I can't get the curly brackets in the string above.....

    Another angle:
    When entering this manually into the interactive window, it worked flawlessly:

    Function1(10,"Jansen",{10-12-2012},2,1)

    Question is however, how do I get Javascript to pass exactly this string?

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Help needed parsing value from javascript to an xbasic function

    Don't know much about javascript.

    Try

    'Function1('+aantalintervallen+',"'+entingnaam+'",{'+eersteentingdatum+'},'+interval+','+volgnummer+')';
    genericXbasicUIFromWorkingPreview(xb);
    There can be only one.

  5. #5
    Banned
    Join Date
    Aug 2003
    Posts
    1,416

    Default Re: Help needed parsing value from javascript to an xbasic function

    Unfortunately, that results in the following error when compiling the component:

    Error:Script:A5W Code line:101 Missing right parenthesis
    It interprets the brackets wrongly. That's why I tried to escape the bracket in the string, to no avail either.

  6. #6
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Help needed parsing value from javascript to an xbasic function

    Ok, maybe

    'Function1('+aantalintervallen+',"'+entingnaam+'",'+chr(123)+eersteentingdatum+chr(125)+','+interval+','+volgnummer+')';
    genericXbasicUIFromWorkingPreview(xb);
    There can be only one.

  7. #7
    Banned
    Join Date
    Aug 2003
    Posts
    1,416

    Default Re: Help needed parsing value from javascript to an xbasic function

    Creative! I have tried dozens of variations today, but THAT one was not yet in it hahaha.

    The grid compiled without a problem, but unfortunately hitting the button gave then a browser error: " chr is not defined ". I guess already in the javascript execution since this is coming from the browser.

  8. #8
    Banned
    Join Date
    Aug 2003
    Posts
    1,416

    Default Re: Help needed parsing value from javascript to an xbasic function

    Hmm. I tried this:

    Code:
    chr(123)+'+eersteentingdatum+'+chr(125)
    and the result that gets parsed to the xbasic function look likes this:

    EntingFunction1(10,"Naam enting",chr(123)+11-02-2010+chr(125),360,1)
    So, it looks like it that the CHR() function is not understood correctly by javascript. Edit: not understood by me that is.

  9. #9
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,649

    Default Re: Help needed parsing value from javascript to an xbasic function

    In JavaScript it's String.fromCharCode(n) where n is your numeric value.

    How about getting the field values directly in the xbasic function from the e object?

  10. #10
    Banned
    Join Date
    Aug 2003
    Posts
    1,416

    Default Re: Help needed parsing value from javascript to an xbasic function

    Yes, that is when using the string object. But how to parse this into an xbasic function? You can't create a new object from the string object, there has to be another solution?
    Or how would you incorporate this into the javascript then Peter, so that it produces the right function string? I simply can't see it??

  11. #11
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,649

    Default Re: Help needed parsing value from javascript to an xbasic function

    Try it like this:

    Code:
    'Function1('+aantalintervallen+',"'+entingnaam+'",'+String.fromCharCode(123)+eersteentingdatum+String.fromCharCode(125)+','+interval+','+volgnummer+')';
    genericXbasicUIFromWorkingPreview(xb);

  12. #12
    Banned
    Join Date
    Aug 2003
    Posts
    1,416

    Default Re: Help needed parsing value from javascript to an xbasic function

    Peter, be glad that you are not near me otherwise I would have kissed you on the forehead !
    That actually worked...... how amazing. Learned yet another thing....

    Thanks a bundle Peter....

Similar Threads

  1. Can I call Xbasic function through javascript ?
    By satyanarayana in forum Application Server Version 11 - Web/Browser Applications
    Replies: 18
    Last Post: 04-06-2017, 07:09 AM
  2. Lesson Learned: Returning Javascript from Xbasic function
    By Terry in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 05-26-2012, 11:19 AM
  3. Multiple embedded file Upload to MS SQL Server 2008 - Xbasic function needed
    By lsprowls in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 01-18-2012, 09:25 PM
  4. Parsing Json results in xbasic from a web service
    By phannon in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 01-05-2012, 05:58 PM
  5. Action JavaScript not available in Grid Javascript function declarations
    By Clipper87 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 09-23-2010, 11:22 AM

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
  •