Alpha Video Training
Results 1 to 2 of 2

Thread: Help needed with basic Ajax callback and SQL Query in Dialog2

  1. #1
    "Certified" Alphaholic
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    1,097

    Default Help needed with basic Ajax callback and SQL Query in Dialog2

    Hi
    I've been going to threads and videos which each one helps with some part of the puzzle, but i am still struggling to achieve what is in my opinion one of the most basic activities in a DB application, that is fetching some data upon some event, then either alert or fill-in some fields.
    I therefore decided to simplify my scenario, could anyone please explain what do i have to do, step by step if possible, for it to work?

    In my dialog, i have some controls: someString1, someNum2, someDate3
    I also have a repeating section with some controls: rsQuery, rsValue, rsQuant, rsTotal
    Of course each part of the dialog is bounded to a different table ( table1 and table2, the latter for the repeating section ).

    The goal: in the onBlur of the rsQuery field, based on it's value if it's not empty, i would like to do the following:
    - run a query in my DB based on values in someNum2, someDate3 and rsQuery
    - if there is no result just display an alert
    - if there is a result, populate with that data the rsValue and someString1.
    - if rsTotal is setup as calculated field rsQuant * rsValue, will it get refreshed automatically?

    That's all, thank you all in advance
    Jaime

  2. #2
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,306

    Default Re: Help needed with basic Ajax callback and SQL Query in Dialog2

    When you put a button on a Dialog you can use Action Javascript to define the button action. (Of course the event could just as easily be on some controls onBlur - it does not have to be a button).

    If you set the button action to 'Ajax Callback' the builder shows you a sample prototype for the xbasic function that is called to handle the callback.
    Inside the sample function, there is extensive documentation in the form of comments that explain how your callback can send a javascript response to populate the dialog.

    If you do not want to hand code the entire callback, then you can use other actions in Action Javascript. For example, when you define your action you can select this action:

    Populate Controls in a Dialog Component with Data from Tables

    this action make an ajax callback to populate the dialog with data for a given primary key value.

    Here is the javascript that it executes:
    var data = {dialog.object}.getValue('SEARCH');
    {dialog.object}.populateControlsFromTable(data,false);

    so, for example, if you want to populate the dialog with the record which has a primary key value of 'foobar', you would write:

    {dialog.object}.populateControlsFromTable('foobar',false);

    if you don't yet know the primary key of the record you want to populate with when you make your callback (you only have some other info, such as the customer lastname)
    then you callback will do a query on the server to find the record that satisfies your query condition. you can then find out what that's record primary key is
    then the response that your xbasic function sends to the browser will be:

    dim jsresponse as c
    jsresonpse = "{dialog.object}.populateControlsFromTable('foobar',false);"

    set the function to return the above value.

    PS You are likely to get better answers than the above answer (i.e. answers with real working code), if you post a small sample app that people can actually run.
    For example, had you built a dialog that was bound to (say) the customer table in northwind.mdb (which we all have) and said -- 'when the user tabs out of the 'contactname' field, i want to populate the dialog with the full record for that customer' you would likely have gotten a response that was less abstract than my response to you here.

Similar Threads

  1. Ajax Callback in Control Onchange Event of Dialog2 Component
    By Dfred in forum Application Server Version 11 - Web/Browser Applications
    Replies: 6
    Last Post: 11-01-2011, 10:49 AM
  2. No AJAX callback for dialog2 buttons when linked by another grid ?
    By Jowell in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 10-31-2011, 05:02 PM
  3. SQL problem when executed in an Ajax Callback
    By ids-dave in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 09-02-2011, 03:54 PM
  4. sql in ajax callback with MIN/MAX functions not accepting identifier
    By workaholic06 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 06-22-2010, 03:21 PM
  5. pass ajax callback item to grid SQL override statement
    By marvinbase in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 05-20-2010, 11:58 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
  •