Insert a Sales Line automatically

jwilderjwilder Member Posts: 263
I have add a field to the Sales Line table and Subform 46 called "Sample". Upon clicking this field it inserts a second line based on the current line (using Line No., Item No. and Qty). I want the second line to be the current line no. + 1. You can probably guess that due to Autsplit and DelayedInsert my original line might not have a line no. yet so I can't increment the new line no. + 1 since it would always = 1.

How can I force the current line to insert so it gets a line no. before inserting the second line. Please note this is not the same as the Temporary Dimension stuff used on Sales and Purchase Subforms. I understand how that works and does not solve my problem.

Answers

  • camecame Member Posts: 12
    Hi,

    But what is the benefit of your solution.
    Why you can't insert first, mark the line you want to "copy" and push a button or call a function who generate the same line +1 (normally +10000)?

    To your solution:
    Otherwise you can try to get the last no. with a temp record or second record on the Sales Line for find die last line in the Sales Line with your relvant filters.
    If you find it, use "Line No" +10000 + 1.
    Then you get die "Line No." for the current Line, that are not inserted yet and die copy line.

    came
  • vaprogvaprog Member Posts: 1,140
    In the OnValidate trigger of the "Sample" field check whether the record has been inserted into the database by trying to FIND a copy of it. If you succeed, you can add the new line. If the record is new, do nothing here. Instead check the "Sample" field in the OnInsert trigger, and if set, insert the sample line there. The "Line No." field is populated here already.
    Do all your coding on the record level, not on the form level, except that you might want to do a CurrForm.UPDATE(TRUE) in the OnAfterValidate trigger if a Sample-line has just been inserted.

    My first attempt was to do the coding on the Form, using the OnValidate trigger of the "Sample" control. But saving the record using CurrForm.SAVERECORD strangely inserted the new line in the wrong place (I had one line with Line No. 10000, and instead of inserting as 20000 it got inserted as 5000).
  • jwilderjwilder Member Posts: 263
    I was given a tip to look at how Extended Text works as that is very similar as to what I was doing.

    The solution that worked perfectly for was to put all the code on the Form OnAfterValidate Trigger. At the very top you must do a Currform.saverecord (now the line no. is finally populated), then the code to insert the second sales line followed by a currform.update(true) to allow the new sales line to show immediately.
  • TejaswiniTejaswini Member Posts: 75
    I have the same issue but I have freight charges field in sales line and this filed get post as item charges as seperate line after posting the item in sales order

    can u please explain me with code...
Sign In or Register to comment.