Development question

tompynationtompynation Member Posts: 398
Hi,

I created a new Type of Sales Line, nl. 'Set'
On the item card i added the Field Set.

So lets say we have Item No.: 1 & 2 both having value 'A' in their Set field
When i now enter a sales line of type Set, select the 'A' set, and then fill in a Qty.
then there should get 2 new Sales Line created under the Set Sales Line. One
for Item '1' & another line for Item '2'

Now this works fine but it is copying the Set also, which isnt desired...

I have this code in the OnValidate for the Quantity field of a Sales Line:

INSERT(TRUE);
lv_LineNo := Rec."Line No." + 10000;
lv_Item.RESET;
lv_Item.SETRANGE(lv_Item.Set,"No.");
IF lv_Item.FINDSET THEN BEGIN
REPEAT
lv_SalesLine.RESET;
lv_SalesLine."Document No." := "Document No.";
lv_SalesLine."Document Type" := "Document Type";
lv_LineNo += 100;
lv_SalesLine."Line No." := lv_LineNo;
lv_SalesLine.VALIDATE(lv_SalesLine.Type,Type::Item);
lv_SalesLine.VALIDATE(lv_SalesLine."No.",lv_Item."No.");
lv_SalesLine.VALIDATE(lv_SalesLine."Location Code","Location Code");
lv_SalesLine.VALIDATE(lv_SalesLine.Quantity,Quantity);
lv_SalesLine.INSERT;
UNTIL lv_Item.NEXT = 0;
END;

This creates the Item lines perfect, but under the item lines, the Set line gets copied ??

How come that this line gets copied?

In the OnInsert trigger, i added following code:

///ESC5.0 - DEV.SID.PUR.A4.001 - TP
lv_SalesLine.RESET;
lv_SalesLine.SETRANGE("Document No.","Document No.");
IF lv_SalesLine.FIND('+') THEN
"Line No." := ROUND(lv_SalesLine."Line No.",1000,'=') + 10000
ELSE
"Line No." := 10000;
///ESC5.0 - DEV.SID.PUR.A4.001 - TP

This is to give the Set line an 'Line No'. as soon as i validate the Quantity

Answers

  • markborgesmarkborges Member Posts: 170
    I think the first "INSERT(TRUE)" should be the cause.

    Please, do one of your tests, and report to me which is the "Line No." of the SET line, before you fill in the Qty. field, and after you fill in the qty, which are the "Line No." of every line.

    For example:

    Before:
    Line 10.000 - Set

    After:
    Line 10.000 - Set
    Line 20.000 - Item 1
    Line 30.000 - Item 2
    Line 40.000 - Set (duplicated)

    :wink:
    Marcelo Borges
    D365 Business Central Solutions Architect
    BC AL/NAV C/AL Developer
    BC Repositories.com
  • tompynationtompynation Member Posts: 398
    Before i fill in the Quantity of the Set Line, the Line No. is still 0
    When i fill in the Quantity and leave the field, the line no is still 0 inside the Onvalidate of the Quantity field
    So i do the insert(true) so that it gets line no 10000

    This is what i get as output on the sales form:
    Type Line No. No. Test No. Description Location Code Quantity Reserved Quantity Unit of Measure Code Unit Price Excl. VAT Line Amount Excl. VAT Line Discount % Qty. to Ship Quantity Shipped Qty. to Invoice Quantity Invoiced Qty. to Assign Qty. Assigned Planned Delivery Date Planned Shipment Date Shipment Date
    Set 10000 EETF5AB EETF5AB 10
    Item 20100 EETF5A EETF5B EPOXY HARS comp A 10 KG 10 10 22/10/01 21/10/01 21/10/01
    Item 20200 EETF5B EETF5B EPOXY HARS comp B 10 KG 10 10 22/10/01 21/10/01 21/10/01
    Set 30000 EETF5AB EETF5AB 10
  • markborgesmarkborges Member Posts: 170
    tompynation,

    By default, when you leave the record, the Navision inserts the record by himself.

    So, if you do "INSERT(TRUE)" then Navision inserts the records twice...

    I think you should do the "Line No." generation directly instead of "INSERT(TRUE)".... This should prevent Navision from Inserting twice.

    :wink:
    Marcelo Borges
    D365 Business Central Solutions Architect
    BC AL/NAV C/AL Developer
    BC Repositories.com
  • tompynationtompynation Member Posts: 398
    well, if i uncomment that Insert(TRUE) it is still happening
  • markborgesmarkborges Member Posts: 170
    You must Comment it.. not uncomment... :wink:
    Marcelo Borges
    D365 Business Central Solutions Architect
    BC AL/NAV C/AL Developer
    BC Repositories.com
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Hi,

    I created a new Type of Sales Line, nl. 'Set'
    On the item card i added the Field Set.

    So lets say we have Item No.: 1 & 2 both having value 'A' in their Set field
    When i now enter a sales line of type Set, select the 'A' set, and then fill in a Qty.
    then there should get 2 new Sales Line created under the Set Sales Line. One
    for Item '1' & another line for Item '2'

    Now this works fine but it is copying the Set also, which isnt desired...

    ...

    This looks like you are trying to create functionality the same as the Kit functionality in the US version of NAV.

    I recommend that you look at the functionality there, and basically use the same logic and data structure as that. I have seen the requirement for Kit functionality in every country I have ever implemented Navision in, and I think its very likely that they will eventually roll this out to W1. So if you use the same logic, it will then be much easier in the future to support your client.
    David Singleton
  • tompynationtompynation Member Posts: 398
    well, i changed my logic so that it new creates the new SalesLines inside the OnInsert method
    and not on the OnValidate of the quantity...

    It works fine now... Thanks for the help and suggestions
Sign In or Register to comment.