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

Fill fields when grid becomes dirty in a grid detail view

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

  • Fill fields when grid becomes dirty in a grid detail view

    I have an grid for editing records. The editing takes place in a detail view. When a user begins typing in any of the fields in the detail view (grid becomes dirty) I want to place the current user ID in the "Modified By" and the current date in the "Modified" fields and subsequently save the date on grid submit.

    Can anyone point me in the right direction for doing this.

    Thanks

  • #2
    Re: Fill fields when grid becomes dirty in a grid detail view

    Hi Lars

    I have a process where first of all there is a session variable called session.fullname.

    In the Server side events I add the following code to the CanUpdateRecord event.

    Code:
    function CanUpdateRecord as v (DataSubmitted as P, Args as p, PageVariables as p, Result as p )
    with PageVariables
    Result.Cancel = .f.
    Result.ErrorHTML = ""
    DataSubmitted.LastUpdated = now()
    DataSubmitted.UpdatedBy = session.fullname
    end with
    end function
    Bear in mind my [UpdatedBy] field is a datetime field in MS SQL. If you are using a dbf date field replace now() with date()
    Glen Schild



    My Blog

    Comment


    • #3
      Re: Fill fields when grid becomes dirty in a grid detail view

      You could use the Grid Client-side Event onDetailViewStateChange. It fires when you start edit a detail view. Do you need specific info about how to use it? How to set Values?

      Comment


      • #4
        Re: Fill fields when grid becomes dirty in a grid detail view

        Thank you Glen!

        David, I would love to have specific information on how to use and set the values in the Grid Client-side Event onDetailViewStateChange. My Javascript skill need work.

        Thanks

        Comment


        • #5
          Re: Fill fields when grid becomes dirty in a grid detail view

          You're going to have to get to your Userid, if you don't already have it. Here's one way. Go to the Grid XBasic functions and add this...

          Code:
          function getCurrUser as c (e as p)
          
          Dim currUser as C
          currUser = a5ws_getCurrentUser()
          if currUser = "" then
          	currUser = "No User Logged In"
          end if	
          getCurrUser = "window['currUser']='" + currUser + "';"
          
          end function
          This gets the current user and assigns it to a window variable.

          Now, get into the Client-Side Events, onDetailViewStateChange and add this...

          Code:
          var currUser = window['currUser'];
          {grid.Object}.setValue('D','YOURFIELDNAME',currUser);
          This gets the window variable and put it into whatever field you want on your detail view.

          Next, staying in Client-Side Events, onGridRender, add this...

          Code:
          {grid.Object}.ajaxCallback('G','{Grid.RowNumber}:all','getCurrUser','','');
          This is an Ajax Callback that runs that function we created named getCurrUser.

          Finally, get into the Detail section Properties, go to the bottom area and, under Editing Properies, you'll see Refresh data on row dirty... uncheck it.

          Overall, when the Grid opens getCurrUser is run and sets up a window variable with the current user.

          Then, when you start editing the detail section, onDetailViewStateChange fires and fills in your field with the current user.

          Just add any other into you want. Dealing with Dates isn't the most fun. Have a look at w3schools.com for lots of javascript stuff and check out how to create and work with dates.

          Comment


          • #6
            Re: Fill fields when grid becomes dirty in a grid detail view

            Thanks David! I will try this out.

            I notice you are using a window variable vs a session variable. Is there any particular reason behind this choice?

            Comment


            • #7
              Re: Fill fields when grid becomes dirty in a grid detail view

              David,

              I placed the your code as you specified and published my component. When I started to edit a field in the detail grid the user id flashed in the appropriate field and then the field went back to information that was previously in that field. (if the field was empty it flashed and went blank and if there was already data it flashed and reverted.)

              Any thoughts?

              Comment


              • #8
                Re: Fill fields when grid becomes dirty in a grid detail view

                Belay my last. I reread your instructions and found the problem.

                Now the issue is that when I press the cancel edits button the fields clear but I cannot close the detail view. I get the alert that says that I have to either cancel edits or save edits in order to close the detail view. Also, when I click the save button the field modified with your code does not get saved to the table.

                Any thoughts on this?

                Comment


                • #9
                  Re: Fill fields when grid becomes dirty in a grid detail view

                  I'll have a look...

                  Comment


                  • #10
                    Re: Fill fields when grid becomes dirty in a grid detail view

                    Lars, my preferred way is tweak the SQL update statement before it hits the database:

                    Do this (serverside function).....

                    Code:
                    function onBeforeSQLCommandExecute as v (e as p)
                    	'inject the DateModified=xx part of the SQL update statement
                    	if e.SQLType = "UPDATE" then
                    		e.a_sql.SQL	= update_DateModified(e.a_sql.SQL)
                    	end if
                    end function

                    ....AND define a update_Modified function as a global Xbasic function for use in any component. Note this function simply replaces the "SET" part of the SQL update statement with "SET DateModified='blah blah' "


                    Code:
                    FUNCTION update_DateModified AS C (myString AS C )
                    	dim myDate as C
                    	if .not. contains(myString, "DateModified") then
                    		myDate = " SET DateModified='" + time("yyyy-MM-dd 0h:0m:0s") + "', "
                    		update_DateModified = stritran(myString, " SET ", myDate)
                    	else
                    		update_DateModified = myString
                    	end if
                    END FUNCTION

                    Comment


                    • #11
                      Re: Fill fields when grid becomes dirty in a grid detail view

                      Mine is saving ok. I have a Grid, with the Detail View displayed. If I make a change in the detail view, I see my username pop into the field. If I click the Save icon I see that change reflected in my Grid just above.

                      But I see the issue with the cancel. That's because onDetailViewStateChange is firing (as it should) on every change, including the undo. So... we can test for the 'change' state and that seems to take care of it.

                      Code:
                      if (e.mode == 'change')
                      {
                      var currUser = window['currUser'];
                      {grid.Object}.setValue('D','YOURFIELDNAME',currUser);
                      }

                      Comment


                      • #12
                        Re: Fill fields when grid becomes dirty in a grid detail view

                        Thanks Andy! I will have to play with your code to see how it could work in my grid.

                        David, Thanks for that fix. I found the following JavaScript code to get the date information
                        Code:
                        function modate() {
                        var mydate=new Date();
                        var theyear=mydate.getYear();
                        if (theyear < 1000);
                        theyear+=1900;
                        var theday=mydate.getDay();
                        var themonth=mydate.getMonth()+1;
                        if (themonth<10);
                        themonth="0"+themonth;
                        var theday=mydate.getDate();
                        if (theday<10);
                        theday="0"+theday;
                        
                        //////EDIT below three variable to customize the format of the date/////
                        
                        var displayfirst=themonth;
                        var displaysecond=theday;
                        var displaythird=theyear;
                        
                        ////////////////////////////////////
                        
                        return 'displayfirst+"/"+displaysecond+"/"+displaythird';
                        }
                        I am wondering how I plug it in to your code so I can see the date information instead of the text string after the "return"

                        Thanks.

                        Comment


                        • #13
                          Re: Fill fields when grid becomes dirty in a grid detail view

                          Take all the code except for the function statement and the return statement and put it into the code that sets the value... something like...

                          Code:
                          if (e.mode == 'change')
                          {
                          var currUser = window['currUser'];
                          {grid.Object}.setValue('D','YOURFIELDNAME',currUser);
                          
                          // Now look after the date.
                          
                          var mydate=new Date();
                          var theyear=mydate.getYear();
                          if (theyear < 1000);
                          theyear+=1900;
                          var theday=mydate.getDay();
                          var themonth=mydate.getMonth()+1;
                          if (themonth<10);
                          themonth="0"+themonth;
                          var theday=mydate.getDate();
                          if (theday<10);
                          theday="0"+theday;
                          
                          var currMth=themonth;
                          var currDay=theday;
                          var currYear=theyear;
                          
                          // Change the following to suit your formatting... e.g. dashes instead of slashes... d/m/y format etc.
                          
                          var currDate = currMth +"/"+ currDay +"/"+ currYear;
                          
                          {grid.Object}.setValue('D','MODIFIED',currDate);
                          
                          }

                          Overall, it would be nice to have a global javascript function that you can call to get you your current date... so you don't have to code it everywhere... but this will help for now.

                          Comment


                          • #14
                            Re: Fill fields when grid becomes dirty in a grid detail view

                            you really should include a js date library for stuff like this. I include datejs and achieve what you are trying to do in 1 or 2 lines!

                            Comment


                            • #15
                              Re: Fill fields when grid becomes dirty in a grid detail view

                              Thanks David!! It works like a champ. Thanks Andy, I am going to check into integrating your recommendations next.

                              Comment

                              Working...
                              X