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

How to prevent "default" records from being deleted??

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

    How to prevent "default" records from being deleted??

    I am trying to find a way using Javascript code to run when the delete key is pressed to FIRST check to see if the hidden sql field called "database_default" for that record is checked (true or false).

    If false, then it can delete the record as normal but if true, I want a message window to pop up saying something like "this record is a default record and can't be deleted".

    I see under Grid Properties, "Javascript - System Events"; there is a canDetailViewDeletRecord event but I don't know how to use it.

    Any ideas?

    Thanks!

    #2
    Re: How to prevent "default" records from being deleted??

    Assuming you are trying to delete from a detail view ...
    Try this in the canDetailViewDeleteRecord event :

    Code:
    // Check value of field Database_Default and do not allow deletion of record if true
    
    var selected = {grid.Object}._getValue('D','DATABASE_DEFAULT',1);
    
    if (selected == 'True'){
       alert('This record is a default record and can not be deleted.');
       return false;
    }
    Bob Moore


    Comment


      #3
      Re: How to prevent "default" records from being deleted??

      Bob,

      I see what you are doing here - excellent idea.

      I must be doing something wrong like missing a comma or something. I have attached a snapshot of my screen error.

      When I run it in browser view from the development station, I get the attached error. When I run it on the website, the JavaScript is ignored and the record is deleted without any messages or errors.

      Can you see anything obvious? I am using the code you wrote.

      Thanks,

      Mike

      Comment


        #4
        Re: How to prevent "default" records from being deleted??

        That's a server side event handler, canDeleteRecord. That event is fired after the Javascript on the client.

        Once again I looked at the doc on the canDetailViewDeleteRecord event and I noticed it passes the rowNumber as a parameter. I hadn't thought to look for the row number because you can only show one row in the detail view however, you may need to use this syntax : e.rowNumber to pass in the row value. I'd have to test this out and dinner is on the table!

        Possible Javascript code change to my original code:

        Code:
        var selected = {grid.Object}._getValue('D','DATABASE_DEFAULT',e.rowNumber);
        Bob Moore


        Comment


          #5
          Re: How to prevent "default" records from being deleted??

          Try:

          var selected = {grid.Object}._getValue('D','DATABASE_DEFAULT')

          You don't need a row number in the detail section.
          Peter
          AlphaBase Solutions, LLC

          [email protected]
          https://www.alphabasesolutions.com


          Comment


            #6
            Re: How to prevent "default" records from being deleted??

            That worked! Very cool!

            Here is a what I used:
            HTML Code:
            // Check value of field DATABASE_DEFAULT and do not allow deletion of record if true
            
            var selected = {grid.Object}._getValue('D','DATABASE_DEFAULT');
            
            if (selected == 'True'){
               alert('This record is a default record and can not be deleted.');
               return false;
            }
            Also, for anyone else reading this, the field name needs to be in UPPERCASE - a mistake I made originally until I saw a comment elsewhere in another post (even though Bob clearly had his example in uppercase, I did not notice that!)

            Thank you Bob and Peter - this is an excellent way to test values before a delete!

            Comment


              #7
              Re: How to prevent "default" records from being deleted??

              Everyone remember ...

              JavaScript is case sensitive and A5v10 uses UPPER_CASE to reference field names in Javascript!
              Bob Moore


              Comment


                #8
                Re: How to prevent "default" records from being deleted??

                Bob and/or Peter,

                Here is a curious thing - the js is working fine. I went in to change the alert message just a little but no mater what I do, the old message continues to pop up - even if I delete the entire js from the system events.

                I removed all the xx.js.gzcache files in the a5webroot folders, even deleted the a5wcmp and re-published it - but still the old js alert will pop up. I went to several different computers thinking that maybe it is stuck in the cookies or session variables but the same old message on other computers as well.

                Why do you think this is not changing? Or where is this js code going that I can't change it? Very interesting!

                Comment


                  #9
                  Re: How to prevent "default" records from being deleted??

                  It's the phantom magical persistent Javascript cache.

                  Only kidding ... You either need to republish the grid component or flush the browser cache.
                  Bob Moore


                  Comment


                    #10
                    Re: How to prevent "default" records from being deleted??

                    Stupid, Stupid, Stupid! User error . . . of course!!

                    OK, I am embarrassed to admit this but hopefully others may learn from this.

                    In the beautifully designed dialog that Selwyn created for us to have access to to these internal functions, "I" did not grasp that the Event itself needs to be highlighted first (canDetailViewDeleteRecord in this case) and then type in the JS code . . . for that Event (of course).

                    I had done this correctly at first but then tried to experiment with copy and pasting code. However when I pasted it back, I neglected to notice which Event I was on - which explains why I could not effect changes to the "other" correct event, no matter what I did - I was on the wrong Event.

                    Anyway, just make sure you have the right Event highlighted on the left column of Events before you add or change JS code!

                    Comment


                      #11
                      Re: How to prevent "default" records from being deleted??

                      OK, now that you all have mastered preventing a deletion based on a value in a field, can you help this newbie write mine? I have a field in the grid named PROD_CODE. I don't want the user to delete the row (or record) if the character value in the field is equal to CHANGE ORDER. I think I have to write this in CanRowDelete system event.

                      That's a simple one, I know, but I'm so new I just need to understand the syntax.

                      I also have a tougher thing I need to do with that grid, and that is to prevent deletion if the PROD_CODE has been used in another table that does NOT have a relationship (cuz it was used in too many relationships and Access would not let me make a relationship for the particular 'child' table). So, in Access I had a lookup query to check to see if the PROD_CODE value was used in that table and if so, I disabled the delete. I am clueless in Alpha as to how to accomplish this.... but, one step at a time.
                      Carol King
                      Developer of Custom Homebuilders' Solutions (CHS)
                      http://www.CHSBuilderSoftware.com

                      Comment


                        #12
                        Re: How to prevent "default" records from being deleted??

                        Carol,

                        Here is the simplest way to handle that I have found. There are some side benefits as well.

                        First, add a button to your row. Call it delete.

                        Under client side properties \ show hide, enter the following code:

                        alltrim(YourFieldHere)="value to be true"

                        Conversely, you can modify above to be the not true value, should be straight forward. Enter the same code in the field below for enable expression

                        Go to the update settings pane for your grid and set Delete Record Control to none. You need to do this to take the A5 standard button off, so it now uses the custom one you added.

                        Next, go add code to bring the new button to life. In-line javascript, onclick row event. Add the following code:

                        {grid.Object}.deleteRow({Grid.RowNumber});

                        Now for side benefits.... if you have a field value that when true you want to prevent deleting. Well, its probably safe to say you dont want users editing either. I have used the same on true code added to each columns enable expression. that way if a certain value is true, it essentially locks the record and prevents deletion.

                        I am sure some of the A5 code jockies have a more code focused way to do what I have done above, but its simple and straightforward. Hope it works for you.

                        Comment


                          #13
                          Re: How to prevent "default" records from being deleted??

                          That worked beautifully, Wayne! Thank you, thank you, thank you. Using the in line javascript on a row event is much more intuitive to me. Biggest problem I'm having is knowing where to put code for things.

                          Only bugaboo I have is that I wanted the grid properties Row Edit Style to be RowOnDemand. But that causes the Delete Record Control to be unavailable in grid properties.... which also causes the A5 standard delete button to show up. I want users to edit rows one at a time because I'm hoping to capture audit info and perhaps give messages particular to values in the row they are editing. HOWEVER, you have made me think and I bet I can create my own edit and submit buttons, too...which means they only work on the row they are on..essentially creating my own RowOnDemand effect. I'm thinking that creating my own edit button will make it easier to look up a value in the line in another table to determine whether it can be edited, OR submitted (same would probably be true with the self-made delete button). more work... off I go.

                          Again, thank you for sending me in the right direction!
                          Carol King
                          Developer of Custom Homebuilders' Solutions (CHS)
                          http://www.CHSBuilderSoftware.com

                          Comment

                          Working...
                          X