Validation on option fields is not working.

liizzliizz Member Posts: 125
Hi all,

I have 3 option fields with their option stings defined too: Status 1(Incomplete, Finish), Status 2(,Postponed, Cancelled) and Status 3(, Approved, Rejected).

Now, the validation is as such: Status 3 can be Approved only if Status 1=Finish and Status 2=Blank.
else it displays an error message.

I have placed codes on Status 3- OnValidate of my customised table
IF NOT("Status 1"="Status 1"::Finish) AND NOT("Status 2"="Status 2"::" ") THEN BEGIN
ERROR('Status 1 should be confirmed and Status 2 should be blank');
END;

But my codes are not working.

Its been a while since am struggling with it ](*,)

Please help.

Thanks
Liizz

Comments

  • gerrykistlergerrykistler Member Posts: 149
    I am not sure what you mean by it is not working, please elaborate.

    I am not sure if you have the check done only if Status 3 is not blank, if not then maybe this is the issue. I have rewritten below also using less characters:

    if "Status 3" <> 0 then
    IF ("Status 1" <> "Status 1"::Finish) AND ("Status 2" <> "Status 2"::" ") THEN
    ERROR('Status 1 should be confirmed and Status 2 should be blank');

    I would also replace your error text with a text constant especially if this will ever be used in a multi-language environment.
    Gerry Kistler
    KCP Consultores
  • liizzliizz Member Posts: 125
    Thanks for your reply. Sorry for not making myself clear in my query..

    IF the field Status 1 is Finish and field Status 2 is blank, then field Status 3 can be set to Approved.
    If not, show an error message.

    I can not have this scenario:
    Status 1:Incomplete
    Status 2: ' '
    This test case should prompt me an error message..

    Yes in my code I have make use of text constant.

    I have tried your codes too but the error message is not being fired..

    Thanks
    Liizz
  • gerrykistlergerrykistler Member Posts: 149
    My mistake, this should work:
    if "Status 3" = "Status 3"::Approved then
    IF not (("Status 1" = "Status 1"::Finish) AND ("Status 2" = "Status 2"::" ")) THEN
    ERROR('Status 1 should be confirmed and Status 2 should be blank');

    You need both to be true so the NOT belongs outside of both true statements.
    Gerry Kistler
    KCP Consultores
  • DenSterDenSter Member Posts: 8,304
    Why not:
    IF "Status 3" = "Status 3"::Approved THEN BEGIN
      TESTFIELD("Status 1","Status 1"::Finish);
      TESTFIELD("Status 2","Status 2"::" ");
    END;
    
  • gerrykistlergerrykistler Member Posts: 149
    Danster,
    More than one way to skin a cat. For once you and I are both correct!
    Gerry Kistler
    KCP Consultores
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DenSter wrote:
    Why not:
    IF "Status 3" = "Status 3"::Approved THEN BEGIN
      TESTFIELD("Status 1","Status 1"::Finish);
      TESTFIELD("Status 2","Status 2"::" ");
    END;
    

    :thumbsup:
    I was just about to write the same thing.
    David Singleton
  • gerrykistlergerrykistler Member Posts: 149
    The difference is if you want to display a more descriptive error message of your own creation, or if the standard TESTFIELD error is enough for the user to understand what they did wrong.
    Gerry Kistler
    KCP Consultores
  • David_SingletonDavid_Singleton Member Posts: 5,479
    The difference is if you want to display a more descriptive error message of your own creation, or if the standard TESTFIELD error is enough for the user to understand what they did wrong.

    Yes that's correct. The problem is that there are so many cryptic error messages in Navision, that users come to expect them. And this way they learn what they did wrong at each step. First you get the message that you made mistake X then a message you made mistake Y. Most users learn faster than being told you made X and Y mistakes please fix them.

    But it does come down a lot to personal preferences. And its really two issues, one being do you want two separate messages or one big one. The other option is to you FIELDERROR, but you don't see the new generation of developers using that much.
    David Singleton
  • Kau_147Kau_147 Member Posts: 84
    Hi Liizz,

    As per your requirement the following code should be work...

    Status3 - OnValidate()

    IF Status3 = Status3::Approved THEN
    IF NOT (Status1 = Status1::Finish) AND NOT (Status2 = 0) THEN
    ERROR('Status 1 should be confirmed and Status 2 should be blank');

    Let me know the result :)

    Best Regards,
    Kavita Bavkar
    Best Regards,
    Kavita Mutha
  • gerrykistlergerrykistler Member Posts: 149
    Kavita,
    That actually does not work as described by the OP and I missed on my first response. Having the NOT on both cases does not cover all situations as it could be Finished and NOT Blank therefore pass the test which is not what the OP was looking for. It needs to test one situation only, Finished and Blank and only if those two conditions are true, then no error. This means the NOT (Finished and Blank) is what is needed in this case.
    Gerry Kistler
    KCP Consultores
  • liizzliizz Member Posts: 125
    Thanks to all for your replies.

    It is working fine. After a good sleep last night, I was able to solve it by myself. :D

    Thanks
    Liizz
  • liizzliizz Member Posts: 125
    Hi Kau_147,

    This solution you gave, I had tried it before but it did not work.
    Kau_147 wrote:
    Status3 - OnValidate()
    IF Status3 = Status3::Approved THEN
    IF NOT (Status1 = Status1::Finish) AND NOT (Status2 = 0) THEN

    Thanks again..
    Only 1 NOT is sufficient and the whole statement should be within that NOT.

    Liizz
Sign In or Register to comment.