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

Check for duplicates/Prevent Duplicates

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

  • Check for duplicates/Prevent Duplicates

    We've got a database on donors for a nonprofit, and there is a tendency for those entering data to create a duplicate record (the same person in twice, at the same address). I'd like to come up with a script to either prevent duplicates from being saved OR allow me to filter out all duplicate records (into a list, maybe) for cleaning.

    Anyone have any ideas? I've currently got a UX where user can create new record, and it gets saved to the table in an afterDialogValidate event. Perhaps something in dialogValidate? I'm not sure how to search through existing records.

  • #2
    Hi,
    to get a list of duplicate it is quite easy use a list based on a query:
    select donorname, count(*) as cnt from donors group by donorname
    to avoid duplicate while entering the data you could use the validation rule in the textbox in alpha

    Hope this help

    Comment


    • #3
      How about something like this?

      Ashampoo_Snap_Friday, June 11, 2021_11h46m38s_002_.png
      Mike Brown - Contact Me
      Programmatic Technologies, LLC
      Programmatic-Technologies.com
      Independent Developer & Consultant

      Comment


      • #4
        Forgive my ignorance- Im not sure how to query to return the count you're referring to- let's say I want to check if a particular name or address is already in the database

        Comment


        • #5
          select count(*) as cnt from yourtable where yourfield=thevar
          this query will return how many times you have a value in a table.


          I think it will be easier to use the validation rules within alpha

          validationrules.png

          Comment


          • #6
            You can rename the file by adding the date+Time+filename. I have a cheat sheet on it if it sounds like something you want.

            Comment


            • #7
              No worries. You said name OR address. So if a duplicate of either is found, no matter what the other value is, you want that counted? Meaning if there is a John Smith at 123 Main St and a Mary Smith at 123 Main St that is a duplicate?
              Mike Brown - Contact Me
              Programmatic Technologies, LLC
              Programmatic-Technologies.com
              Independent Developer & Consultant

              Comment


              • #8
                Originally posted by PaulAmmoun View Post
                select count(*) as cnt from yourtable where yourfield=thevar
                this query will return how many times you have a value in a table.


                I think it will be easier to use the validation rules within alpha

                validationrules.png
                She didn't mention having a list on this UX. Is there a list with data? Or is it just a enter new record type of UX. The specifics are important.
                Mike Brown - Contact Me
                Programmatic Technologies, LLC
                Programmatic-Technologies.com
                Independent Developer & Consultant

                Comment


                • #9
                  In the dialogValidate server side event,
                  search the table to see if the customer name and/or address are already in the donor table.
                  Any simple match would indicate a known donor.
                  I supplied basic code to search your table for current duplicates.

                  Code:
                  select count(*),<donor name>
                  FROM <donor table>
                  where <filter>
                  group by <donor name>
                  having count(*) > 1
                  order by <donor name>
                  Gregg
                  https://paiza.io is a great site to test and share sql code

                  Comment


                  • #10
                    Thanks for the suggestions, everyone. I think I've got it working well! I set up cross-file validation rules on the address field to check if an address exists, and then I use the following function to see if a particular name already exists. (I even added the contingency that it will check to see if someone is entered as a spouse. Ex: John and Mary Smith - if I try to enter a Mary Smith it will catch it).

                    Code:
                    function dialogValidate as p (e as p)
                    
                    dim cn as SQL::Connection
                    dim rs as SQL::ResultSet
                    dim sqlUpdate as c
                    dim argsUpdate as SQL::Arguments
                    dim itsOpen as L
                    dim dothething as L
                    dim itsDone as p
                    dim dupCount as n = 0
                    
                    'Test for open connection
                    itsOpen=cn.open("::name::CONNECTION STRING")
                    
                    sqlUpdate = "select count(*) FROM records where (first_name = '"+e.dataSubmitted.first+"' or spouse = '"+e.dataSubmitted.spouse+"' or first_name = '"+e.dataSubmitted.spouse+"' or spouse='"+e.dataSubmitted.first+"') and last_name = '"+e.dataSubmitted.last+"';"
                    dothething = cn.Execute(sqlUpdate,argsUpdate)
                    itsDone = cn.ResultSet.toString()
                    dupCount = val(itsDone.value)
                    
                    if dupCount >= 1
                    dialogValidate.hasError = .t.
                    dialogValidate.errorText = "There is already a record with this name."
                    else
                    dialogValidate.hasError = .f.
                    end if
                    
                    end function
                    I am thinking I want to include an "override" option. Like "I know that it already exists, but I need to enter it anyway". Thoughts on how I might do that? I'm thinking some sort of message box in the if statement. Appreciate any suggestions!

                    Comment


                    • #11
                      Maybe add an unbound, and hidden, textbox you can populate with a 1 if they choose to override. Then, in the dialogValidate just check if it's a 1 or not.

                      Code:
                      function dialogValidate as p (e as p)
                      
                      if e.dataSubmitted.overide = "1" then
                         'Do nothing. User override.
                      else
                         'Check for duplicates
                      dim cn as SQL::Connection
                      dim rs as SQL::ResultSet
                      dim sqlUpdate as c
                      dim argsUpdate as SQL::Arguments
                      dim itsOpen as L
                      dim dothething as L
                      dim itsDone as p
                      dim dupCount as n = 0
                      
                      'Test for open connection
                      itsOpen=cn.open("::name::CONNECTION STRING")
                      
                      sqlUpdate = "select count(*) FROM records where (first_name = '"+e.dataSubmitted.first+"' or spouse = '"+e.dataSubmitted.spouse+"' or first_name = '"+e.dataSubmitted.spouse+"' or spouse='"+e.dataSubmitted.first+"') and last_name = '"+e.dataSubmitted.last+"';"
                      dothething = cn.Execute(sqlUpdate,argsUpdate)
                      itsDone = cn.ResultSet.toString()
                      dupCount = val(itsDone.value)
                      
                      if dupCount >= 1
                      dialogValidate.hasError = .t.
                      dialogValidate.errorText = "There is already a record with this name."
                      else
                      dialogValidate.hasError = .f.
                      end if
                      end if
                      end function
                      Mike Brown - Contact Me
                      Programmatic Technologies, LLC
                      Programmatic-Technologies.com
                      Independent Developer & Consultant

                      Comment


                      • #12
                        mikeallenbrown using this method, is there a way to choose to override AFTER checking for duplicates?

                        Comment


                        • #13
                          Sure, you could put the duplicate checking code into a xbasic function (removing it from the dialogValidate event). When the user presses submit it runs the xbasic function. The xbasic function would need to be modified some to continue with a saving of data or ask the user if they want to override.
                          Mike Brown - Contact Me
                          Programmatic Technologies, LLC
                          Programmatic-Technologies.com
                          Independent Developer & Consultant

                          Comment


                          • #14
                            mikeallenbrown Thanks! It's working. Here's my finished code. May it help someone else!
                            Code:
                            function duplicateCheck as c (e as p)
                            
                            dim cn as SQL::Connection
                            dim rs as SQL::ResultSet
                            dim sqlUpdate as c
                            dim argsUpdate as SQL::Arguments
                            dim itsOpen as L
                            dim dothething as L
                            dim itsDone as p
                            dim dupCount as n = 0
                            dim js as c = ""
                            
                            'Test for open connection
                            itsOpen=cn.open("::name::connectionstring")
                            
                            sqlUpdate = "select count(*) FROM records where (first_name = '"+e.dataSubmitted.first+"' or spouse = '"+e.dataSubmitted.spouse+"' or first_name = '"+e.dataSubmitted.spouse+"' or spouse='"+e.dataSubmitted.first+"') and last_name = '"+e.dataSubmitted.last+"';"
                            dothething = cn.Execute(sqlUpdate,argsUpdate)
                            itsDone = cn.ResultSet.toString()
                            dupCount = val(itsDone.value)
                            
                            if dupCount >= 1
                            
                            js = <<%str%
                            var title = 'Duplicate Found';
                            var html = '<p>There is a record with this name already. Do you want to enter it anyway?</p>';
                            var type = 'yn';
                            var onClose = function (btn) {
                            if (btn == 'yes') {
                            // save their work then close the window
                            {dialog.object}.runAction("saveAndClose");
                            } else if (btn == 'no') {
                            // close the window
                            {dialog.object}.runAction("close");
                            } else {
                            // cancel - do nothing
                            }
                            };
                            A5.msgBox.buttons.yes = {html: 'Yes', className: 'msgbtnyes'};
                            A5.msgBox.buttons.no = {html: 'No', className: 'msgbtnno'};
                            
                            A5.msgBox.show(title, html, type, onClose);
                            
                            %str%
                            
                            
                            end if
                            duplicateCheck = js
                            end function

                            Comment


                            • #15
                              Good job getting it working.
                              I noticed you defined argsUpdate, and even use the arguments in the query, but you never created any arguments.
                              Arguments are helpful in protecting your stuff from sql injection, even though you're not likely to experience
                              such an attack from within your organization.
                              with that said,

                              Code:
                              argsUpdate.Set("first",e.dataSubmitted.first)
                              argsUpdate.Set("spouse",e.dataSubmitted.spouse)
                              argsUpdate.Set("last",e.dataSubmitted.last)
                              dupCount = sql_lookup(cn,"records","last_name = :last and (first_name in (:first,:spouse) or spouse in (:first,:spouse))","count(*)",argsUpdate)
                              Gregg
                              https://paiza.io is a great site to test and share sql code

                              Comment

                              Working...
                              X