Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Referencing grid field values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Referencing grid field values

    I am new to development with Alpha Software products, so please bear with me. I realize this is probably a very simple question.

    I have successfully created a grid based on a connection to an SQL table. I want to be able to reference the values of fields in the current record shown in the live or working preview so I can fire off an insert query (for a different table) based on them.

    I have searched all of the online resources I can find but I cannot seem to figure out how to reference these fields. I'd love to be able to test my code from an interactive window too, but that, of course, depends on properly referencing the fields and their values.

    In summary then, how do I reference fields in a grid in my code and from the interactive window? Or where can I learn how to do this?

    #2
    Re: Referencing grid field values

    If you are talking about referencing them in your server side events (or an ajax callback), they will be in the "e" object. Place a debug(1) in your server side event (or xbasic function in the case of an ajax callback) and you can explore the variables there. If you are using a grid that isn't editable and an ajax callback you will need to check the option to "compute current row data"; but I digress.

    The notes inside of the different server-side events and the ajax callback function prototype will tell you where to look for the field data but most likely it will be something like this which is taken from the function prototype notes:
    Code:
    'In addition, the 'e' object contains:
    'e._currentRowDataOld - (only if the grid is editable) - original value in the current row before field was edited.
    '	examples:  e._currentRowDataOld.lastname, e._currentRowDataOld.firstname
    'e._currentRowDataNew as p - current field values in the current row.
    '	examples:	e._currentRowDataNew.lastname, e._currentRowDataNew.firstname
    'e._currentRowKeys - an array containing primary key field values for the current row
    '	example: If the primary key for the table that the grid is based on is 'Lastname' and 'Firstname',
    '	e._currentRowKeys[1] will contain the value for 'Lastname' and e._currentRowKeys[2] will contain the value for 'Firstname'
    If you want to access them with javascript you should just go to your button/field's event (onclick or whatever you are using) and open it for editing. Inside you can select text mode and then click on "insert a grid method" which is a blue hyperlink near the bottom left. You can explore the different functions available there and their usage notes. Generally, you'd be looking at the getValue method which is described like this inside the example:

    Code:
    //Read value in 'LASTNAME' field from the Grid part, row 4. Note that field name must be uppercase.
    var lname = {grid.object}.getValue('G','LASTNAME',4);
    //read value in 'LASTNAME' field from the Grid part, 'current row'. 
    //Note that field name must be uppercase.
    var lname = {grid.object}.getValue('G','LASTNAME',{grid.rowNumber});
    
    Note that {grid.rowNumber} cannot be used in client-side Javascript or Global Javascript functions. 
    Instead, you must use the {grid.Object}.getSelectedRow() method of the Grid object to get the current row. For example: 
    var rn={grid.Object}.getSelectedRow();
    var lname = {grid.object}.getValue('G','LASTNAME',rn);
    
    //Read value in 'LASTNAME' field in the Search part.
    var lname = {grid.object}._getValue('S','LASTNAME');
    //read value in 'LASTNAME' field in the Detail View part.
    var lname = {grid.object}._getValue('D','LASTNAME');
    //Getting value of 'range' fields in the Search part. You can't use .getValue(). You have to use low level Javascript.
    var val1 = $('{grid.componentname}.S.STARTDATE').value;
    var val2 = $('{grid.componentname}.S._TO.STARTDATE').value;
    So, the first example is server-side using Xbasic
    The second example is client-side using Javascript.
    Last edited by -Jinx-; 04-30-2014, 04:54 PM.

    Comment


      #3
      Re: Referencing grid field values

      Jinx, thank you! Your answer was exactly what I need to solve my issue. The debug(1) command gave me the exact object names. ~Bill

      Comment


        #4
        Re: Referencing grid field values

        Great reference thanks Jinx

        One more tip for anyone else reading this...

        (and I am using A5v12)


        For client side events, you can use {Grid.RowNumber}
        and in fact I found it worked
        better than {grid.Object}.getSelectedRow()


        The reason is the order of events...

        If you need to reference the current row number in an OnClick event,
        the OnClick event triggers first, before the grid realises a new row was selected


        To give a real example

        Insert a button in a grid row

        Put some javascript in the OnClick event of the button.
        Go to text mode and enter
        Code:
        var rownum={grid.Object}.getSelectedRow();
        alert('Row = ' + rownum);
        Preview the grid and click the button a few times on different rows.

        What you will notice is:

        - The alert box always shows row 1 as the first click, regardless of which row you click on

        - for subsequent clicks, the alert will show you the previous row you clicked on, not the current one.


        So it seems the correct way to get the current row number for an OnClick event is use {Grid.RowNumber}

        This works as expected, returning the current row number of the button you are clicking

        Code:
        var rownum={Grid.RowNumber};
        alert('Row = ' + rownum);

        Comment


          #5
          Re: Referencing grid field values

          Hi Michael,
          Almost you answered to my question http://msgboard.alphasoftware.com/al...getSelectedRow

          But how can I do this on onDialogInitialize event:

          e.javascript = <<%txt%
          var po = {grid.object}.getParentObject();
          if (po)
          {
          //var rn=po.getSelectedRow(); //this works
          var rn = {grid.RowNumber}; //this not works
          var IdPlanAchizitii = po.getValue('G','IDPLANACHIZITII',rn);
          {dialog.Object}.setValue('IDPLANACHIZITII',IdPlanAchizitii,false);
          }
          else alert('not po');
          %txt%

          Bill, sorry for pollute you thread.

          Comment


            #6
            Re: Referencing grid field values

            Hi Catalin,

            Maybe it's where you are setting reference to your PO object

            I think you need to replace {grid.object}.getParentObject()
            with {dialog.object}.getParentObject()

            i.e.

            replace
            Code:
            var po = {grid.object}.getParentObject();
            with
            Code:
            var po = {dialog.object}.getParentObject();

            I am guessing this, because you are using onDialogInitialize event, so this current code is running in a Dialog (even though the parent is a grid, and the PO object reference will be to the parent grid)

            Comment


              #7
              Re: Referencing grid field values

              Also to be extra sure everything runs way you expect

              in your parent grid, in the Action Javascript "Open a UX Component" properties

              You might want to set "Use cached UX Component" to False (checkbox off).

              And now the OnDialogInitialize event will trigger every single time the popup UX is opened.

              Comment

              Working...
              X