problem With Sales Line

MRQMRQ Member Posts: 73
Hi
I am trying to write this field from Sales line to the another table called Accommodation the field is "Documant Type" "documant No." "Line No."
and then give "No series" to fourth field called "No." i write the follwing code to do this

In the salse line Form i add button and write the following code in onPush event
Call function called InsertAccom take the prameter Rec
Accommodation.InsertAccom(Rec);

FORM.RUN(FORM::"Accommodation Card",Accommodation);

and this is the code in the function InsertAccom this function take parameter (VAR salesLIne : Record "Sales Line")
InsertAccom(VAR salesLIne : Record "Sales Line")

INIT;
"Documant No." :=salesLIne."Document No.";
"Documant Type" :=salesLIne."Document Type";
"Line No.":=salesLIne."Line No.";
INSERT(TRUE);

and in the on insert triger write the following cade to give the "No. serise"
to filed "No."
IF "No."='' THEN BEGIN
 TravelSetup.GET;
 TravelSetup.TESTFIELD(TravelSetup."Accommodation No." );
 NoSeriesMgt.InitSeries(TravelSetup."Accommodation No.","No. Series",0D,"No.","No. Series");
END;


The problem is that when i select seles line from the sales order and press
the button every thing goes right New Rec was Inserted in the Accommodation Table And Take New No." but if i select another sales line and press the button this line take the same "No." of the previous Rec

Unless I close The sales order Form and open it again
and then select sales line and press the button in this case the New Accommodation Rec take New" No."

Comments

  • ShenpenShenpen Member Posts: 386
    I suppose there is a
    WITH AccomLine do begin
       INIT;
    

    there?

    Use CLEAR instead of INIT. Or maybe RESET, but I always use CLEAR...

    in the C/AL help of INIT:
    Comments
    The system does not initialize primary key or timestamp fields.
    [/quote][/code]

    Do It Yourself is they key. Standard code might work - your code surely works.
  • DenSterDenSter Member Posts: 8,307
    The button is on the header form, and Rec on the Header is a record in the Sales Header table. If you want to do something with the sales line, you should check the line button and see how Navision accesses the line records.
  • kinekine Member Posts: 12,562
    Problem is the INIT and clearing PK. Correct code is:
    INIT;
    "Documant No." :=salesLIne."Document No.";
    "Documant Type" :=salesLIne."Document Type";
    "Line No.":=salesLIne."Line No.";
    "No." := '';
    INSERT(TRUE);
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • MRQMRQ Member Posts: 73
    thanx you Shenpen, kine
    you are right the Problem is the INIT and clearing PK.
    now its working thamk alot

    dear DenSter the button is on the sales line not in the header
  • DenSterDenSter Member Posts: 8,307
    Then you have a customized form. The standard sales order form does not have buttons on the subform.
Sign In or Register to comment.