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

Conditional Expression for Field Rule Uniqueness Test

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

    Conditional Expression for Field Rule Uniqueness Test

    I want to create a field rule uniqueness test based on three fields in my table. I can do it by typing arrdate+complex+unit in "value of the expression must be unique" box. But ... I want to make this test conditional on the unit field not equal to zero. I cannot find an expression that will make this work. Any ideas.

    #2
    Re: Conditional Expression for Field Rule Uniqueness Test

    Deb,

    Maybe
    Code:
    if(unit<>0, arrdate+complex+unit, ui_msg_box("Attention!","This is not a unique record and will not be saved!"))
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________



    Comment


      #3
      Re: Conditional Expression for Field Rule Uniqueness Test

      Mike,

      Thanks for the idea. I tried it and Alpha5 considers it an invalid or incomplete expression ... a common Alpha5 message along with incorrect data type. I typed your suggestion correctly and double checked open and close "()".

      To better explain my problem, I can accomplish the field rule uniqueness test by creating an expression that concatenates the fields ... arrdate+complex+unit. This works fine. BUT ... I don't want to perform this test if the unit=0. In my application, unit=0 means the unit has not been assigned, therefore the uniqueness test is not wanted. I can have several unit=0s within a complex for a given arrival date. However, if a property has been assigned "unit<>0", the uniqueness test will prevent a double booking.

      Here's the logic a want. Test the uniqueness of this expression "arrdate+complex+unit" if the unit<>0. Otherwise, skip the test and let me enter multiple unit 0s for the same arrdate and complex.

      Any other ideas?

      Deb

      Comment


        #4
        Re: Conditional Expression for Field Rule Uniqueness Test

        You can't make the test of unit part of the uniquness validation but you can add a custom validation

        unit > 0
        There can be only one.

        Comment


          #5
          Re: Conditional Expression for Field Rule Uniqueness Test

          can't make the test of unit part of the uniquness validation
          Thanks Stan! I have been writing my own validations and such so I do not use many field rules (obviously!)...but thinking about it and reading the question over it makes sense to me--analogous to defining a word's meaning and using it as part of the definition!
          Mike
          __________________________________________
          It is only when we forget all our learning that we begin to know.
          It's not what you look at that matters, it's what you see.
          Henry David Thoreau
          __________________________________________



          Comment


            #6
            Re: Conditional Expression for Field Rule Uniqueness Test

            Stan,

            Thanks for the suggestions, but how do I create a custom validation for a uniqueness test. What is the function for "is this expression unique"? I've also thought about creating a field event, but I come up with the same question. What is the code Alpha5 creates for a field rule to validate a unique expression?

            Deb

            Comment


              #7
              Re: Conditional Expression for Field Rule Uniqueness Test

              You don't create "a custom validation for a uniqueness test".

              You have your uniqueness test. Now create a custom validation for the unit field so that it can't be zero. Net result is the same?
              There can be only one.

              Comment


                #8
                Re: Conditional Expression for Field Rule Uniqueness Test

                Stan,

                Your effort is appreciated, but I'm not communicating my goal. In some instances, I want units to equal zero (to be assigned at a later date). If units equal zero, I don't want to validate a unique expression with the unit as one of the components. Otherwise, I want the unique validation expression to be arrdate+trim(complex)+unit. The unique value validation test and the custom validation tests appear to be mutually exclusive of each other. Therefore, this does not solve my problem.

                Thank you for your interest.

                Deb

                Comment


                  #9
                  Re: Conditional Expression for Field Rule Uniqueness Test

                  I did not understand that the units field could be zero.

                  You will likely have to code the cansave event for your data entry form and use the KEY_UNIQUE() function to create your own validation. I believe this wouldn't be particularly hard to do.

                  In pseudo code...

                  Code:
                  IF units > 0
                  	'do nothing
                  ELSE
                  	IF key_unique("yourindextagname")
                  		'do nothing
                  	ELSE
                  		ui_msg_box("Record","Combination of fields is not unique")
                  		cancel()
                  	END IF
                  END IF
                  There can be only one.

                  Comment


                    #10
                    Re: Conditional Expression for Field Rule Uniqueness Test

                    Stan,

                    Thanks for the code suggestion. I'll work with it and let you know the results.

                    Deb

                    Comment


                      #11
                      Re: Conditional Expression for Field Rule Uniqueness Test

                      Looks like I was approaching this the hard way.

                      Create an index for your table with a filter like screenshot "index".

                      Create a custom validation for the unit field like screenshot "custom validation".

                      See if that takes care of it.
                      There can be only one.

                      Comment


                        #12
                        Re: Conditional Expression for Field Rule Uniqueness Test

                        To Stan and all the others who have made suggestions,

                        I appreciate all your ideas, but so far none have worked and my client will not appreciate the bill for my effort. So I'll try to come up with a user work-around for this duplicate check problem.

                        I've followed some other threads on uniqueness tests and created an index call Dup_check using the fields that I want to test for uniqueness.

                        I've tried solving the problem with a field event dialog box (either OnSaveRecord or CanSaveRecord) using this code

                        If(key_unique("dup_check"),.f.,.t.) as a condition.

                        With conditional field events, you must invert the truth logic because the conditional expression wants a true result. So I tried to pop up a message box that says "Failed Duplicate Check". Just to be sure, I've tried it both ways and I still get the same results regardless of the truth statement. I get a failed duplicate check even when I shouldn't. By the way, I had simplified the logic and eliminated the unit=0 check, knowing the user could override the warning. But even the single argument does not work. Also, I always get a message 'FR:Rule_System is not an open window whenever I click on the little xy box. Regardless, I type the expression into the box without the expression editor and look at the code.

                        On a different tact, I've tried custom validation in the field rules and this works better than field events. I've been able to validate one expression or the other but not both. Can anyone see a problem with this logic?

                        If(val(unit)=0.or.key_unique("dup_check"),.t.,.f.)

                        The dup_check index logic works, but I could have accomplished that easily with the standard unique value expression field rule. However, when the value of unit equals 0, I still get a false result. If anyone sees a problem with my logic, I'm all eyes.

                        Deb

                        Comment


                          #13
                          Re: Conditional Expression for Field Rule Uniqueness Test

                          Well duh!

                          I finally came up with a field rule uniqueness test that works and it goes back to an earlier suggestion which didn't work because I used unit>0 instead of val(unit)>0. Here is the successul code.

                          if(val(unit)>0,arrdate+trim(property),.t.)

                          Is there a forest out there somewhere?

                          Thanks for all your ideas.

                          Deb

                          Comment


                            #14
                            Re: Conditional Expression for Field Rule Uniqueness Test

                            Hi Deb,
                            Since your unit field is a character type and not numeric, unit > "0" should also work. Somewhere in here is a tip about setting numeric fields with default values of 0 so that they are not null. Also logical fields should have a default value set too like .f.
                            Robin

                            Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                            Comment

                            Working...
                            X