Coding to copy previous sales order line

ellusiveladyellusivelady Member Posts: 23
HELP NEEDED

Added SubOrderNo code 20 to Sales Header table.

Added OrderRefNo text 30, SubOrderNo code 20 to Sales Line table.

When Sales Order form is opened, Sales Order Line will setrange based on Sales Header SubOrderNo.

By default, Sales Line SubOrderNo will be the same as Sales Header SubOrderNo.

eg. Sales Header: Document No. = 10010
SubOrderNo = 1

Sales Line: (1st line) OrderRefNo = ER1 Order (manually key)
SubOrderNo = 1
Item = 133
(2nd line) OrderRefNo = ER1 Order (should be auto)
SubOrderNo = 1
Item = 135

Each time i create a new line, I want the system to automatically copy the OrderRefNo from the previous line. Only applicable to 2nd line onwards.

I can't assign another variable(eg. storeOrderRef) to OrderRefNo. It will only work for this SubOrderNo. Cause if I create another SubOrderNo (i.e. 2) for Document No. 10010, and if I go back to the previous SubOrderNo (i.e. 1), I cannot use variable storeOrderRef cause the OrderRefNo will now be different(cause it will reflect that of SubOrderNo 2).

I hope my explanation is clear enough and you understand what I'm trying to say.

Thanks.

Answers

  • kinekine Member Posts: 12,562
    1) You can use the PopulateAllFields property on the form to fill all fields with the value to which the field is filtered on (if it is simple value).

    2) If your new field is not part of the primary key of the Lines (it means that you extended the PK of the table), you will have problems with the AutoSplitKey functionality when entering the lines into the order if you will filter the lines in this way... I recommend to thing about that...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krzychub83krzychub83 Member Posts: 120
    Hi Ellusivelady

    Try to put some code, to the "No." validate trigger of the sales line. SalesLine is a local variable of type Record from table 37.
      // Copy rec filters 
      SalesLine.Copyfilters(Rec);
    
      // If SalesLines are not filtered by SubOrderNo then You need it to filter 
      // the record set:
      // SalesLine.SETFILTER(SubOrderNo , NowUsedSubOrderNo );
      
      IF SalesLine.COUNT > 1 THEN
      BEGIN
        // THERE IS AT LEAST ONE RECORD OF SEALS LINE
        SalesLine.FIND('+');
        REC.OrderRefNo := SalesLine.OrderRefNo;
      END
      ELSE
      BEGIN
        // You don't have any rec. created yet. 
        REC.OrderRefNo := 'What ever You want';
      END;
    

    If this is not helping You, try to write the problem more clearly.
    I will try to help You then.
    GoodLuck
  • ellusiveladyellusivelady Member Posts: 23
    hi All,

    thanks so much for your help.

    But to kine, unfortunately, I can't use the PopulateAllFields as my data defers.

    As for krzychub83, tanx for ur code. I did tried that before i post here but it didn't entirely work. :-s tanx though.

    In my main Sales Order, I can have multiple suborders.

    I managed to solved it though. I created a table to store the unique suborder number. From there, if user select a particular number, the details will follow accordingly. dat seems to be d best way out. on top of that, i remove the autosplitkey function n automaticaly assign my own line no.

    Thanks once again all.
Sign In or Register to comment.