Automatic posting of item charges


How to post the item charges automatically while posting the item in sales order, when we click the post button in sales order the item charges should be post in background.

Can any one please explain me

explain your question please i don’t understand exactly the problem

I have created a field carrier charges in sales line and in sales order subform I added this field, when I am posting the item in sales order the carrier charges should come as item charges, the new line of item charges should be post in background while posting the item
how can I achieve this?

Hello Govardhini,

I think you should set the control in codeunit [Sales-Post].
In codeunit [Sales-Post] you can insert the freight charge in sales line before posting.
Please remember that you have to create an item no. or a G/L Account for the charge.

Thank you,

Can u please suggest me the code for it

In that code unit where I have to write my code?

Before insert into shipment line, you can set a filter about freight charge <> 0, then copy it as a line as normal one.
For example, you can coding as:

SalesLineNo := SalesLineNo + 10000; //copy it to next line.
recSOLine.VALIDATE(“Document Type”,“Document Type”);
recSOLine.VALIDATE(“Document No.”,“No.”);
recSOLine.VALIDATE(“Line No.”,SalesLineNo);
recSOLine.VALIDATE(“Location Code”,SalesLine.“Location Code”);
recSOLine.VALIDATE(“Qty. to Ship”,1);
recSOLine.VALIDATE(“Qty. to Invoice”,0);

//to calculate the freight charge amount

recSOLine.VALIDATE(“Unit Price”,SalesLine.“Freight Charge” * SalesLine.“Qty. to Ship”); //Order

recSOLine.VALIDATE(“Line Amount”,recSOLine.“Unit Price”);
recSOLine.VALIDATE(“Planned Delivery Date”, SalesLine.“Planned Delivery Date”);

recSOLine.VALIDATE(“Gen. Bus. Posting Group”, SalesLine.“Gen. Bus. Posting Group”);
recSOLine.VALIDATE(“Gen. Prod. Posting Group”, SalesLine.“Gen. Prod. Posting Group”);
recSOLine.VALIDATE(“VAT Bus. Posting Group”, SalesLine.“VAT Bus. Posting Group”);
recSOLine.VALIDATE(“VAT Prod. Posting Group”, SalesLine.“VAT Prod. Posting Group”);


And don’t forget to copy document dimensions.

Thank you so much

recSOLine is which record??

How to filter that freight charges<>0 ?? I am new to Navision please explain me

recSOLine → Sales Line
freight charges<>0 → recSOLine.setfilter(“freight charges”,’<>%1’,0);

Ok thank you

But I am getting the error while posting that you have to specify document no.

firstly, you have to set filter in recSOLine to match Sales Header record.

If you didn’t figure out, you can write me a letter, I’ll tell you how to code it.


How to match it to sales header record using setfilter?

Please help me

And How to copy document dimensions??

But in posted documents like posted sales invoice I am getting only one line of item I didn’t get second line as item charges

Please suggest me

The second line of item charges should be added to posted sales invoice and in value entries while posting the item

Please don’t mind I am asking u lot of questions

PostItemChargeLine(RecSalesLine : Record “Sales Line”)
IF SalesLine.Type = SalesLine.Type ::Item THEN BEGIN
RecSalesLine.SETRANGE(“Document No.”,SalesHeader.“No.”);
RecSalesLine.SETFILTER(“Carrier Charges”,’<>%1’,0);
SalesLineNo := SalesLineNo + 30000;
RecSalesLine.VALIDATE(“Document Type”,SalesLine.“Document Type”::Order);
RecSalesLine.VALIDATE(“Document No.”,SalesHeader.“No.”);
RecSalesLine.VALIDATE(“Line No.”,SalesLineNo);
RecSalesLine.VALIDATE(Type,SalesLine.Type::“Charge (Item)”);
RecSalesLine.VALIDATE(“Location Code”,SalesLine.“Location Code”);
RecSalesLine.VALIDATE(Description,‘Item Freight Charges’);
RecSalesLine.VALIDATE(“Qty. to Ship”,1);
RecSalesLine.VALIDATE(“Qty. to Invoice”,0);
RecSalesLine.VALIDATE(“Unit Price”,SalesLine.“Carrier Charges” * SalesLine.“Qty. to Ship”);
RecSalesLine.VALIDATE(“Line Amount”,RecSalesLine.“Unit Price”);
RecSalesLine.VALIDATE(“Planned Delivery Date”,SalesLine.“Planned Delivery Date”);
RecSalesLine.VALIDATE(“Gen. Bus. Posting Group”,SalesLine.“Gen. Bus. Posting Group”);
RecSalesLine.VALIDATE(“Gen. Prod. Posting Group”,SalesLine.“Gen. Prod. Posting Group”);

As per your suggestion I have written the code like this

you have to add your function in this loop :
IF (“Document Type” = “Document Type” :: Order) and Ship THEN BEGIN …

and also if you want the field shows in sales return order,
you have to add your function in this loop:
IF (“Document Type” = “Document Type” :: “Return Order”) and Receive THEN BEGIN …
Notice that you have to change “Qty. to ship” to “Return Qty. to Receive”, also some different fields between Order and Return Order.

Please help me in this question

U have written the code to calculate the freight charge amount, but when I am posting I got the error that unit price must not be zero, it means it didn’t get my freight charges it is taking as 0

how to solve this???