Find the Current Record

Hi All,

How to find out the current record present in sales order based on this record I want to add the new line of item charges automatically and I want to write the code by creating the function in code unit 80 and want to call it for the post button because when I hit the post button the new line of item charges should be added automatically

for example 1st line as item and it's document no. is 1900
and 2nd line as charge(Item) and it's document no. is taking as null

please suggest me to achieve this

Best Answer

Answers

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    you can use sales header no to assign to 2nd line
  • TejaswiniTejaswini Member Posts: 75
    Okay thank you

    could you please tell me the meaning of this error
    xaglmcuv4vip.png
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    record is already existing in Item Charge Assignment (Sales) table with those values.
    Are you hard coded line no. to 20000?
  • TejaswiniTejaswini Member Posts: 75
    how to solve it
  • TejaswiniTejaswini Member Posts: 75
    yes
  • TejaswiniTejaswini Member Posts: 75
    yes it is existing then how can I invoice it
  • timosman369timosman369 Member Posts: 16
    youre duplicating records

    what have you done to get this error?
  • TejaswiniTejaswini Member Posts: 75
    I have written the code for adding the new line of item charges automatically
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    first you need to get whether there is any records with above filters except Line no. and then find the last line no. and increase it by 10000
  • TejaswiniTejaswini Member Posts: 75
    I didn't understand
    could you please tell me clearly
    I am new to navision
  • timosman369timosman369 Member Posts: 16
    like mohana said, you need to check if there is already line no generated for that document no and then based on that start from 10000 or add 10000 to last used line no
  • mohana_cse06mohana_cse06 Member Posts: 5,504
  • TejaswiniTejaswini Member Posts: 75

    WITH SalesHeader DO BEGIN
    GRecSalesLine.RESET;
    GRecSalesLine.SETRANGE("Document Type","Document Type");
    GRecSalesLine.SETRANGE("Document No.","No.");
    GRecSalesLine.SETRANGE(Type,GRecSalesLine.Type::"Charge (Item)");
    IF GRecSalesLine.FINDFIRST THEN BEGIN
    NewItemChargeAssignment.INIT;
    NewItemChargeAssignment."Document Type" := GRecSalesLine."Document Type"::Order;
    NewItemChargeAssignment."Document No." := "No.";
    NewItemChargeAssignment."Document Line No." := GRecSalesLine."Line No.";
    NewItemChargeAssignment."Line No." := GRecSalesLine."Line No.";
    NewItemChargeAssignment."Applies-to Doc. Line No." := NewItemChargeAssignment."Line No.";
    NewItemChargeAssignment."Applies-to Doc. No." := GRecSalesLine."Document No.";
    NewItemChargeAssignment."Applies-to Doc. Type" := GRecSalesLine."Document Type"::Order;
    NewItemChargeAssignment."Item Charge No." := 'I-FREIGHT';
    NewItemChargeAssignment."Item No." := SalesLine."No.";
    NewItemChargeAssignment.Description := SalesLine.Description;
    NewItemChargeAssignment.VALIDATE("Qty. to Assign",1);
    NewItemChargeAssignment.VALIDATE("Unit Cost",GRecSalesLine."Amount Including VAT");
    NewItemChargeAssignment.VALIDATE("Amount to Assign",GRecSalesLine."Amount Including VAT");
    NewItemChargeAssignment.INSERT;
    END;
    END;

    I have written the code like this because I don't want to use the item charge assignment feature without using that feature I want to invoice the item charges by assigning the charges to the item

    But before I want to invoice this record of item charges get inserted in 5809 table
  • TejaswiniTejaswini Member Posts: 75
    Please suggest me the code to remove this error
  • TejaswiniTejaswini Member Posts: 75
    Thank You I got it.
Sign In or Register to comment.