Alpha Video Training
Results 1 to 18 of 18

Thread: Get and Set Values from a child grid to parent grid

  1. #1
    Member
    Real Name
    Tony Watts
    Join Date
    Mar 2010
    Posts
    442

    Default Get and Set Values from a child grid to parent grid

    I have a grid that has a button that opens another (target) grid that I use to lookup values, make and save edits.
    The two grids are linked and filtered so that only the current record is opened in the target grid.
    I use the following to lookup values in the target grid and set values back into the parent grid.

    //Get a pointer to the parent component object that opened this grid.
    var po = {grid.Object}.getParentObject();

    //Get the values from the grid (you can define as many as you like)
    var firstname = {grid.object}.getValue('G','first_name',{grid.rowNumber}); //golfer table
    var lastname = {grid.object}.getValue('G','last_name',{grid.rowNumber}); //golfer table
    var city = {grid.object}.getValue('G','city',{grid.rowNumber}); //golfer table
    var cellphone = {grid.object}.getValue('G','last_name',{grid.rowNumber}); //golfer table
    var notify = {grid.object}.getValue('G','notify',{grid.rowNumber}); //golfer table


    //If this Grid does not have a parent then 'po' will be false.
    if (po) {
    po.setValue('first_name',firstname); //golfer table
    po.setValue('last_name',lastname); //golfer table
    po.setValue('city',city); //golfer table
    po.setValue('cellphone',cellphone); //golfer table
    po.setValue('notify',notify); //golfer table
    }

    //Close the grid.
    {grid.Object}.closeContainerWindow(this);

    Works perfectly!

    When I add another field from the golfer

  2. #2
    "Certified" Alphaholic mikeallenbrown's Avatar
    Real Name
    Mike Brown
    Join Date
    Nov 2009
    Location
    United States
    Posts
    1,879

    Default Re: Get and Set Values from a child grid to parent grid

    Quote Originally Posted by twwtc View Post
    Works perfectly!
    Great!
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant

  3. #3
    Member
    Real Name
    Tony Watts
    Join Date
    Mar 2010
    Posts
    442

    Default Re: Get and Set Values from a child grid to parent grid

    Sorry ...... the last part of my post did not survive the copy and paste!

    My problem is that I have tried to add a field to the "get value" and "set value" into the parent grid, but from a different table than the other fields.
    I tried adding the following:

    var Handicap = {grid.object}.getValue('G','HANDICAP',{grid.rowNumber});

    po.setValue('HANDICAP',Handicap);


    HANDICAP is a field in the parent grid, but is from a different table than the other fields "set" in the previous post.

    Is this possible and/or can anyone see what I'm doing wrong?
    Thanks
    Tony

  4. #4
    "Certified" Alphaholic mikeallenbrown's Avatar
    Real Name
    Mike Brown
    Join Date
    Nov 2009
    Location
    United States
    Posts
    1,879

    Default Re: Get and Set Values from a child grid to parent grid

    You set value isn't working because you are missing some important parameters (like which row are you setting).

    Here is some sample code I copied from Alpha's documentation. I think it'll be of help...

    Code:
    //Set value in 'LASTNAME' field from the Grid part, row 4. Note that field name must be uppercase.
    {grid.object}.setValue('G','LASTNAME',4,'Smith');
    
    //Set value in 'LASTNAME' field from the Grid part, 'current row'. 
    //Note that field name must be uppercase.
    {grid.object}.setValue('G','LASTNAME',{grid.rowNumber},'Smith');
    
    //Set value in 'LASTNAME' field in the Search part.
    {grid.object}.setValue('S','LASTNAME','Smith');
    
    //set value in 'LASTNAME' field in the Detail View part.
    {grid.object}.setValue('D','LASTNAME','Smith');
    
    //set the value in 'FAVORITECOLOR'. Assume that 'FAVORITECOLOR' is a multi-valued field (e.g. a Checkbox control or a Dropdown control configured to allow multiple values):
    {grid.Object}.setValue('S','FAVAORITECOLOR[]',['alpha','beta','gamma']);
    Notice that the fieldname has a trailing [] - to indicate that it is an array of values, and the values you want to set are passed in in the form of a Javascript array.
    
    //Setting value of 'range' fields in the Search part. You can't use .setValue(). You have to use low level Javascript.
    $('{grid.componentname}.S.STARTDATE').value = '12/1/2010';
    $('{grid.componentname}.S._TO.STARTDATE').value = '12/31/2010';
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant

  5. #5
    Member
    Real Name
    Tony Watts
    Join Date
    Mar 2010
    Posts
    442

    Default Re: Get and Set Values from a child grid to parent grid

    Mike
    The following works

    var po = {grid.Object}.getParentObject();

    //Get the values from the grid (you can define as many as you like)
    var firstname = {grid.object}.getValue('G','first_name',{grid.rowNumber});
    var lastname = {grid.object}.getValue('G','last_name',{grid.rowNumber});
    var city = {grid.object}.getValue('G','city',{grid.rowNumber});
    var cellphone = {grid.object}.getValue('G','last_name',{grid.rowNumber});
    var notify = {grid.object}.getValue('G','notify',{grid.rowNumber});
    //var Handicap = {grid.object}.getValue('G','HANDICAP',{grid.rowNumber});

    //If this Grid does not have a parent then 'po' will be false.
    if (po) {
    po.setValue('first_name',firstname);
    po.setValue('last_name',lastname);
    po.setValue('city',city);
    po.setValue('cellphone',cellphone);
    po.setValue('notify',notify);
    //po.setValue('Handicap',Handicap);


    }

    //Close the grid.
    {grid.Object}.closeContainerWindow(this);



    This does not work: (the only difference is what is in red)

    var po = {grid.Object}.getParentObject();

    //Get the values from the grid (you can define as many as you like)
    var firstname = {grid.object}.getValue('G','first_name',{grid.rowNumber});
    var lastname = {grid.object}.getValue('G','last_name',{grid.rowNumber});
    var city = {grid.object}.getValue('G','city',{grid.rowNumber});
    var cellphone = {grid.object}.getValue('G','last_name',{grid.rowNumber});
    var notify = {grid.object}.getValue('G','notify',{grid.rowNumber});
    var Handicap = {grid.object}.getValue('G','HANDICAP',{grid.rowNumber});

    //If this Grid does not have a parent then 'po' will be false.
    if (po) {
    po.setValue('first_name',firstname);
    po.setValue('last_name',lastname);
    po.setValue('city',city);
    po.setValue('cellphone',cellphone);
    po.setValue('notify',notify);
    po.setValue('Handicap',Handicap);


    }

    //Close the grid.
    {grid.Object}.closeContainerWindow(this);

    I was trying to keep it simple and copy a method that worked.

    Thanks for replying
    Tony

  6. #6
    "Certified" Alphaholic mikeallenbrown's Avatar
    Real Name
    Mike Brown
    Join Date
    Nov 2009
    Location
    United States
    Posts
    1,879

    Default Re: Get and Set Values from a child grid to parent grid

    There is something going on with the handicap part of the grid then. It's the same syntax as your other code you said was working. That's the best I can offer with out sample components.

    Is handicap misspelled in either the parent or child grid?
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant

  7. #7
    Member
    Real Name
    Tony Watts
    Join Date
    Mar 2010
    Posts
    442

    Default Re: Get and Set Values from a child grid to parent grid

    I've checked and re-checked the spelling.
    Is this a normal and regular procedure ...... to set the value of a field (handicap) from table "x" (parent table) with a field (handicap) value from table "y" (child table)?
    If so, does it manner that the fields in each of the two tables ("x" and "Y") use the exact same field names?
    Thanks
    Tony

  8. #8
    "Certified" Alphaholic mikeallenbrown's Avatar
    Real Name
    Mike Brown
    Join Date
    Nov 2009
    Location
    United States
    Posts
    1,879

    Default Re: Get and Set Values from a child grid to parent grid

    A sample component is needed. Setting data from parent to child and vice versa is a very normal thing that's done. It's a very straight forward method.
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant

  9. #9
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,642

    Default Re: Get and Set Values from a child grid to parent grid

    what happens if it's all lowercase like everything else that works and shouldn't?
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

  10. #10
    Member
    Real Name
    Tony Watts
    Join Date
    Mar 2010
    Posts
    442

    Default Re: Get and Set Values from a child grid to parent grid

    Hi Peter
    I tried with all lower case and still it did not work ....

    What about the select statement for child and the parent grid?

    The field that I am not able to set a value for is "players.handicap" which is not in the select statement for the child grid.

    Child Grid select statement
    SELECT golfer_id, Handicap, first_name, last_name, address, city, state, zc, cellphone, email, notify
    FROM golfers
    ORDER BY last_name, first_name

    Parent Grid select statement
    SELECT *
    FROM (Players Players
    INNER JOIN Teams Teams
    ON Players.Team_ID = Teams.Team_ID
    INNER JOIN golfers golfers
    ON Players.Golfer_ID = golfers.golfer_id )

    Could that be my problem?
    Thanks
    Tony

  11. #11
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,642

    Default Re: Get and Set Values from a child grid to parent grid

    Is there a value there?

    do an alert..

    var notify = {grid.object}.getValue('G','notify',{grid.rowNumber});
    var Handicap = {grid.object}.getValue('G','HANDICAP',{grid.rowNumber});
    alert(Handicap};[/QUOTE]
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

  12. #12
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,642

    Default Re: Get and Set Values from a child grid to parent grid

    I just noticed you said this 'My problem is that I have tried to add a field to the "get value" and "set value" into the parent grid, but from a different table than the other fields.'
    The question is what table and where do you get it? The value you are returning is coming from the same parent as the others. Maybe the join is wrong.
    e.g. this simple select statement works, so check you are returning a value.
    SELECT
    *
    FROM person person
    INNER JOIN active active
    ON person.Active = active.Active
    Last edited by peteconway; 11-02-2019 at 12:23 AM.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

  13. #13
    Member
    Real Name
    Tony Watts
    Join Date
    Mar 2010
    Posts
    442

    Default Re: Get and Set Values from a child grid to parent grid

    Peter
    Below are my select statements

    Player's Grid
    Parent table is: Players
    player_id
    team_id
    golfer_id
    handicap

    SELECT Players.Player_ID, Players.Team_ID, Players.Golfer_ID, Players.handicap, Teams.Team_ID AS Team_ID1, Teams.Tourn_ID, golfers.golfer_id AS golfer_id1, golfers.first_name, golfers.last_name, golfers.city, golfers.cellphone, golfers.handicap
    FROM (Players PlayersI
    INNER JOIN Teams Teams
    ON Players.Team_ID = Teams.Team_ID
    INNER JOIN golfers golfers
    ON Players.Golfer_ID = golfers.golfer_id )

    Golfer's (lookup) Grid
    Child table is: Golfers
    golfer_id
    first_name
    last_name
    city
    cellphone
    handicap

    SELECT golfer_id, first_name, last_name, city, cellphone, handicap,
    FROM golfers
    ORDER BY last_name, first_name

    I can set the value of golfers.handicap in the players grid, from the value in the lookup grid - golfers.handicap
    but still can't set the value of players.handicap in the players grid, from the value in the lookup gird - golfers.handicap

    Thanks for your help
    Tony

  14. #14
    Volunteer Moderator
    Real Name
    James A. Talbott, Jr.
    Join Date
    Apr 2000
    Location
    Lexington, KY
    Posts
    1,460

    Default Re: Get and Set Values from a child grid to parent grid

    Have you tried putting a debugger in your javascript and looking at the process in Firefox or Chrome developers tools?
    That might point out the issue.

    Jay
    Jay Talbott
    Lexington, KY


  15. #15
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,642

    Default Re: Get and Set Values from a child grid to parent grid

    Tony I can't get to not work, everything strait forward, send me your components, i'll take a look.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

  16. #16
    Member
    Real Name
    Tony Watts
    Join Date
    Mar 2010
    Posts
    442

    Default Re: Get and Set Values from a child grid to parent grid

    Thanks Jay for replying.
    I have never put a debugger in javascript, but I'll give it a try.

    Peter
    I'll send the components
    Thanks

    Tony

  17. #17
    Volunteer Moderator
    Real Name
    James A. Talbott, Jr.
    Join Date
    Apr 2000
    Location
    Lexington, KY
    Posts
    1,460

    Default Re: Get and Set Values from a child grid to parent grid

    Put this is the javascript

    debugger;

    and then turn on the Chrome or FF developers tools before running the javascript.

    Jay
    Jay Talbott
    Lexington, KY


  18. #18
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,642

    Default Re: Get and Set Values from a child grid to parent grid

    on a side note - I built a test case for the problem to test - again can't get it to fail, so it does work. As I said before check the select statement, ensure your field is updatable in the grid. AA seems to be quicker more flexible these days with the list control and the viewbox. samples
    teams.PNG
    Players2.PNG

    Pete
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

Similar Threads

  1. How to set values into QBE fields when child grid opens from parent grid
    By Narayan in forum Mobile & Browser Applications
    Replies: 0
    Last Post: 04-24-2015, 10:19 AM
  2. In a linked grid, how do you pass values from parent to child?
    By Rida Alhasan in forum Application Server Version 11 - Web/Browser Applications
    Replies: 3
    Last Post: 03-12-2013, 01:37 PM
  3. How do I access linked grid Parent Field > Child Field linking values in child grid?
    By TheSmitchell in forum Application Server Version 11 - Web/Browser Applications
    Replies: 5
    Last Post: 10-02-2012, 04:04 PM
  4. Pass values from Child Grid to Parent Grid
    By cavj1 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 10-19-2010, 05:53 PM
  5. passing field values from a parent to a child grid
    By finditqwik in forum Application Server Version 8
    Replies: 0
    Last Post: 03-28-2007, 12:30 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
  •