How to conditionally cancel an F3 New Record???

GaryDGaryD Member Posts: 66
Hello all, here's my problem. Let's say I have a sales order with 1 line with an item (line 10000) on it and 3 lines of extended description for that item on lines 20000, 30000 and 40000. The user is on line 30000 when he hits F3. Currently this will insert a line between 30000 and 40000, splitting up the extended text that was already on the form. So I want to not allow an insert if the Attached to Line No. field on the line the user is on has a non-zero value. I've tried generating an error in the OnNewRecord trigger but that closes out the entire form. Thanks for the help!

Answers

  • kinekine Member Posts: 12,562
    Try to check the condition in OnInsert on the table. There you can look at previous and next line and call Error if the inserted line is in position where you want to not allow to create it.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • GaryDGaryD Member Posts: 66
    Thanks Kine. That would work in a pinch but would not trigger until the record was saved so the user would get the new blank line inserted into the form, then start filling it out and only then would they get the message that they cannot insert at that point. It would be nice if I could prevent all of that and give them the message right after they hit F3.
  • kinekine Member Posts: 12,562
    I am afraid that there will not be easy solution for this, because nearly every error called from form will close the form (except OnValidate and may be other triggers). But e.g. you can display some Icon on the line to show the users that attempt to insert the line will end with error to give them "early warning"... :whistle:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • GaryDGaryD Member Posts: 66
    Thanks again Kine. That gives me enough information to know what I Need to do. I appreciate your help.
  • SavatageSavatage Member Posts: 7,142
    I don't know if it would work but how about forcing the line no to always be the last#

    Perhaps some code guru's can clean this up - if it even works at all..
    I would guess you need it on a "Line no." trigger.
    IF Status = Status::Open
     THEN BEGIN
      Salesline.RESET;
      Salesline.SETRANGE("Document Type",xRec."Document Type");
      Salesline.SETRANGE("Document No.",xRec."Document No.");
       IF Salesline.FIND('+')
        THEN  "Line No." := xRec."Line No."+ 10000;
       END;
    
    It's rough, but an idea
    
  • GaryDGaryD Member Posts: 66
    Thanks Savatage, but the users will sometimes want to insert a line at a certain point. And I can't determine if they really wanted to insert the line at that point or if they were on the wrong line when they hit F3, so I don't want to automatically set their line to be the last line. I went with Kine's suggestion and am using the records OnInsert to display an error that the user is on a line that can't be split.
  • Dave_SDave_S Member Posts: 17
    I have put the following code in the Sales Order subForm onInsertRecord to disallow users using F3 to add lines to EDI orders
    IF SalesHeader."Order Source" = SalesHeader."Order Source"::EDI THEN BEGIN
      MESSAGE(Text65005);
      EXIT;
    END;
    

    It displays the message then returns to the line F3 was pressed on.
  • kinekine Member Posts: 12,562
    Dave_S wrote:
    I have put the following code in the Sales Order subForm onInsertRecord to disallow users using F3 to add lines to EDI orders
    IF SalesHeader."Order Source" = SalesHeader."Order Source"::EDI THEN BEGIN
      MESSAGE(Text65005);
      EXIT;
    END;
    

    It displays the message then returns to the line F3 was pressed on.

    I will preffer to add code into OnInsert trigger of the table which will call error instead message... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • vaibhavgoel_1vaibhavgoel_1 Member Posts: 7
    normally.. you can write code on validate and so on.. n even if u write code on these other conditions, it will work fine... if u have delayed insert property on... with delayed property on, and with some logical code, you can have ur problem resolved....
Sign In or Register to comment.