on post of purchase order how to show error msg if field is empty?

mdsrmdsr Member Posts: 163
Hi all,
I am trying to add error mssage if any field in purchase order is empty while posting.for that i have added a code on Post action as
IF "Buy-from Vendor No."='' THEN 
    BEGIN
      ERROR('Error:Empty field'+FIELDCAPTION("Buy-from Vendor No.")+'Please Add Data in field.');
    END;
  IF "Buy-from Vendor Name"='' THEN
    BEGIN
    ERROR('Error:Empty field '+FIELDCAPTION("Buy-from Vendor Name")+'Please Add Data in field.');
    END;
  IF "Buy-from Contact No."='' THEN
    BEGIN
    ERROR('Error:Empty field '+FIELDCAPTION("Buy-from Contact No.")+'Please Add Data in field.');
    END;
  IF "Buy-from City"='' THEN
    BEGIN
    ERROR('Error:Empty field '+FIELDCAPTION("Buy-from City")+'Please Insert Data in field.');
    END;
  IF Structure='' THEN
    BEGIN
    ERROR('Error:Empty field '+FIELDCAPTION(Structure)+'Please Insert Data in field.');
    END;
  IF "PO Type"="PO Type"::" " THEN 
    BEGIN
      ERROR('Error:Empty field '+FIELDCAPTION("PO Type")+'Please Insert Data in field.');
    END;
for line level of Purchase order code like this

[code]RecPurchLine.RESET;
    RecPurchLine.SETRANGE(RecPurchLine."Document No.","No.");
    //RecPurcaseLinehLine.SETRANGE(RecPurchLine."Document Type","Document Type");
    IF RecPurcaseLine.FIND('-') THEN 
      BEGIN
      //REPEAT
        IF RecPurchLine.Type=RecPurchLine.Type::" " THEN
          BEGIN
         MESSAGE('Error:Empty field Type Please Insert Data in field.');
          END;
          IF RecPurchLine."No."='' THEN
          BEGIN
           MESSAGE('Error:Empty field '+FIELDCAPTION("No.")+'Please Insert Data in field.');
          END;
       //UNTIL RecPurcaseLine.NEXT=0;
       END;
but even if field having value then also massage pop up and repeat infinite times as we close that massage
how i can wtite code so that it will work properly

thanks in advance.

Answers

  • navuser1navuser1 Member Posts: 1,329
    better to use TESTFIELDS function thru Events
    Now or Never
  • mdsrmdsr Member Posts: 163
    but user want message pop up when field empty and for line level data of po how to do this?
  • navuser1navuser1 Member Posts: 1,329
    TESTFIELDS gives you pop up conditionally. And Events management helps you to achieve your goal without modifying the standard code.
    Now or Never
  • mdsrmdsr Member Posts: 163
    When I tried testfield on post action it not showing field of line level of Purchase order such as type , No., Location Code,Descriptionline
    TESTFIELD(Type);
    TESTFIELD(Location Code);
    
  • sorenhinrupsorenhinrup Member Posts: 136
    As others have mentioned, events are the best solution for this.
    where have you placed the code from the original post? In codeunit 90? I think the reason you get the messages, even though the fields are filled, is because the rec where you have put your code is not the purchase document, but the posted document, which is being created.

    If you setup an event as following:
    b1b7as39svja.png

    Then you will have the Purchase Header Rec as VAR, and you can find the attatched lines.
  • mdsrmdsr Member Posts: 163
    I have put my code at POST action of purchase order page .so when user click on POST it will show error if any filed is empty. I don't know about event that much but by adding code also it should work I guess. but I don't clear how that code write so we get error message for empty field.
Sign In or Register to comment.