Alpha Video Training
Results 1 to 13 of 13

Thread: Ajax Call Back - Add record issue

  1. #1
    Member
    Real Name
    Steve Kent
    Join Date
    May 2011
    Posts
    139

    Default Ajax Call Back - Add record issue

    I am trying to use an AJAX callback function to add a new record to a table. I am getting an error

    Error executing Ajax callback function 'RunUpdate' Error reported was: Variable is of different type

    The xbasic code is

    Function RunUpdate as c (e as c)

    DIM e_name as c = e._currentRowDataOld.employee_name
    DIM p_num as c = e._currentRowDataOld.procedure.number
    DIM p_name as c = e._currentRowDataOld.procedure.name
    DIM tblTrain as P

    tblTrain = table.open("training")

    tblTrain.enter_begin()
    tblTrain.employee_name = e_name
    tblTrain.procedure_number = p_num
    tblTrain.procedure_name = p_name
    tblTrain.enter_end()
    tblTrain.close()

    End Function


    I'll admit that I am very new at this stuff. So far I have spent about 4 hours on this and can't understand the issue.

    What I am trying to do is pull data from the detail view of and append a table with the data.

    Any help would be gratefully appreciated.

    Steve

  2. #2
    Banned
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Ajax Call Back - Add record issue

    Hey Steve,

    In your DBF table...

    e_name is character
    p_num is character
    p_name is character

    is that right?

  3. #3
    Banned
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Ajax Call Back - Add record issue

    Hey Steve,

    In your DBF table...

    e_name is character
    p_num is character
    p_name is character

    is that right?

    And...

    Do you have your syntax correct here?

    DIM e_name as c = e._currentRowDataOld.employee_name
    DIM p_num as c = e._currentRowDataOld.procedure.number
    DIM p_name as c = e._currentRowDataOld.procedure.name

    "dot" name and number?

    Ooops... how did that double post happen?

  4. #4
    Member
    Real Name
    Steve Kent
    Join Date
    May 2011
    Posts
    139

    Default Re: Ajax Call Back - Add record issue

    Good catch.. but not the problem

    Correct code is

    Function RunUpdate as c (e as c)

    DIM e_name as c = e._currentRowDataOld.employee_name
    DIM p_num as c = e._currentRowDataOld.procedure_number
    DIM p_name as c = e._currentRowDataOld.procedure_name
    DIM tblTrain as P

    tblTrain = table.open("training")

    tblTrain.enter_begin()
    tblTrain.employee_name = e_name
    tblTrain.procedure_number = p_num
    tblTrain.procedure_name = p_name
    tblTrain.enter_end()
    tblTrain.close()

    End Function



    And all the variables are character

  5. #5
    Member
    Real Name
    Jim Coltz
    Join Date
    Oct 2005
    Location
    Western Pennsylvania
    Posts
    600

    Default Re: Ajax Call Back - Add record issue

    Steve,

    Function RunUpdate as c (e as c)
    this needs to be
    Code:
    function RunUpdate as c (e as p)
    "e" is a pointer variable that is passed into the function.

    You'll also want to look at path aliases http://alphafivewiki.com/Path+and+Co...String+Aliases and change the line
    Code:
    tblTrain = table.open("training")
    to
    Code:
    tblTrain = table.open("[PathAlias.ADB_Path]\training")
    Jim Coltz
    Alpha Custom Database Solutions, LLC
    A5CustomSolutions.com
    jimcoltz@a5customsolutions.com

  6. #6
    Banned
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Ajax Call Back - Add record issue

    Could you zip and post the two tables involved... the table that the grid is based on and the training table?

    I just ran your code in my grid. My grid is based on a dbf table with the same fields as you're writing, plus an auto increment emp_id field. Now, even though the grid is based on my "trainingdev" table, I am writing back out to the same table. That should not matter. I'm not getting any errors. New records are being inserted. Except for the emp_id field, all fields in the target table are character.

  7. #7
    Banned
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Ajax Call Back - Add record issue

    Nice Jim... missed that one. That's the error. I ran Steve's code, but I let Alpha create the function so it was created correctly.

  8. #8
    Member
    Real Name
    Steve Kent
    Join Date
    May 2011
    Posts
    139

    Default Re: Ajax Call Back - Add record issue

    Training_New.ziptraining-1.zipI tried Jim's code corrections and it wasn't working for me. Attached are the files.

    Steve

  9. #9
    Banned
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Ajax Call Back - Add record issue

    I'll have a look, but changing my working code Function header to the incorrect code of "Function RunUpdate as c (e as c)" created the error you're reporting.

  10. #10
    Banned
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Ajax Call Back - Add record issue

    Hey Steve,

    Training-1.zip contains the training table... excellent. But Training_New.zip contains a dialog with similar, but different code. Is that the right one?

  11. #11
    Member
    Real Name
    Steve Kent
    Join Date
    May 2011
    Posts
    139

    Default Re: Ajax Call Back - Add record issue

    Training_R.zip

    You are right. My mistake.. Please disregard the Training-New File with Training_R attached.

    Thanks for taking a look.

    Steve

  12. #12
    Banned
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Ajax Call Back - Add record issue

    Hey Steve,

    Your code, with Jim's corrections is fine, but I'm guessing that your error message changed and that you're no longer getting "variable is of different type". You're now getting a message about sub-elements not being there. This is because you are running code from the Detail section of a grid BUT the Ajax Callback is set to the Grid part of the grid. Get into your Detail section, into the onClick event of the Create New Record button, and into the Ajax Callback Action dialog. The 2nd option in the list is Submit Part which is currently set to Grid. But you're calling RunUpdate from the Detail section. Change this option to DetailView and you should be ok.

    Here's a couple of other tips. In your question always specify what area you're working from that is most likely causing the problem... Search, Grid, Detail, Dialog, Repeating Section etc.

    When you're having trouble with Ajax Callbacks, or Xbasic code in general, put a debug(1) line into your code - where ever you want to start looking at the code in debugging mode - and then run your component in working mode. The code will break when executed and you can walk through to find offending sections. This is how I found that e._currentRowDataOld was not being set at all which led me back to how the callback was being called.

  13. #13
    Member
    Real Name
    Steve Kent
    Join Date
    May 2011
    Posts
    139

    Default Re: Ajax Call Back - Add record issue

    David, your da man. Such a simple solution. In the course of trying different things, I alternated with the two different error messages. It was driving me nuts.

    Much thanks, I really appreciated your time. I hope someday to have enough knowledge to give back on this board.

    Steve

Similar Threads

  1. refresh embedded grid in dialog as result of ajax call back not possible?
    By cptutrecht in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 06-13-2012, 06:32 AM
  2. Replies: 0
    Last Post: 02-01-2012, 05:09 AM
  3. Ajax Call back problem with 'e.V'
    By cFlat7 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 11-04-2010, 06:35 PM
  4. Ajax call back post-populating fields from sql
    By phannon in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 07-22-2010, 01:42 PM
  5. check box Selection Ajax Call Back
    By amarcelo in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 05-06-2010, 03:41 PM

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
  •