Find the Current Record

Tejaswini
Member Posts: 75
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
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
0
Best Answer
-
Hi,
First find out why line 10000 is existing. If all according to plan then something like this should solve it:
IF GRecSalesLine.FINDFIRST THEN BEGIN
clear(NewItemChargeAssignment);
NewItemChargeAssignment.setrange("Document Type",GRecSalesLine."Document Type"::Order);
NewItemChargeAssignment.setrange("Document No.","No.");
NewItemChargeAssignment.setrange("Document Line No.",GRecSalesLine."Line No.");
if NewItemChargeAssignment.findlast then
NewLineNo := NewItemChargeAssignment."line no." + 10000
else
NewLineNo := 10000;
clear(NewItemChargeAssignment);
NewItemChargeAssignment.INIT;
NewItemChargeAssignment."Document Type" := GRecSalesLine."Document Type"::Order;
NewItemChargeAssignment."Document No." := "No.";
NewItemChargeAssignment."Document Line No." := GRecSalesLine."Line No.";
NewItemChargeAssignment."Line No." := NewLineNo;5
Answers
-
you can use sales header no to assign to 2nd line0
-
record is already existing in Item Charge Assignment (Sales) table with those values.
Are you hard coded line no. to 20000?0 -
how to solve it0
-
yes
0 -
yes it is existing then how can I invoice it0
-
youre duplicating records
what have you done to get this error?0 -
I have written the code for adding the new line of item charges automatically0
-
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 100000
-
I didn't understand
could you please tell me clearly
I am new to navision0 -
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 no0
-
show us the code what you have written0
-
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
0 -
Please suggest me the code to remove this error0
-
Hi,
First find out why line 10000 is existing. If all according to plan then something like this should solve it:
IF GRecSalesLine.FINDFIRST THEN BEGIN
clear(NewItemChargeAssignment);
NewItemChargeAssignment.setrange("Document Type",GRecSalesLine."Document Type"::Order);
NewItemChargeAssignment.setrange("Document No.","No.");
NewItemChargeAssignment.setrange("Document Line No.",GRecSalesLine."Line No.");
if NewItemChargeAssignment.findlast then
NewLineNo := NewItemChargeAssignment."line no." + 10000
else
NewLineNo := 10000;
clear(NewItemChargeAssignment);
NewItemChargeAssignment.INIT;
NewItemChargeAssignment."Document Type" := GRecSalesLine."Document Type"::Order;
NewItemChargeAssignment."Document No." := "No.";
NewItemChargeAssignment."Document Line No." := GRecSalesLine."Line No.";
NewItemChargeAssignment."Line No." := NewLineNo;5 -
Thank You I got it.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions