C/AL code

Hi Experts,

Is there any way to write the code for adding the new line of item charges automatically by not using the .INSERT in the code

Please suggest me the code

Not really sure what you mean, but if you want to insert new records from C/AL, then you need to use the INSERT function.
What else did you have in mind?

I want to post the item charges automatically by posting the item in sales order and I want to display it in value entries like there should be first line as item and next line should be item charges
for this I have written the code like this

ValueEntry.SETRANGE(“Item Ledger Entry No.”,ItemLedgEntry.“Entry No.”);
ValueEntry.“Item Ledger Entry Type” := ValueEntry.“Item Ledger Entry Type”::Sale;
ValueEntry.“Carrier Charges” := ItemJnlLine.“Carrier Charges”;
ValueEntry.“Sales Amount (Actual)” := ItemJnlLine.“Carrier Charges”;
ValueEntry.Description := ‘Item Freight Charges’;
ValueEntry.“Item Charge No.” := ‘I-FREIGHT’;
ValueEntry.“Document No.” := ItemLedgEntry.“Document No.”;
ValueEntry.“Entry No.” := ValueEntryNo+1;
ValueEntry.“Item Ledger Entry No.” := ItemLedgEntry.“Entry No.”;
ValueEntry.“Item No.” := ItemLedgEntry.“Item No.”;

but this is a direct insertion

how can I write the code to achieve this
Please help me

Yes, seems you know what to do, but what is your question then?

I have written the code for posting the item charges to sales invoice line also like

IF (SalesLine.Type = SalesLine.Type ::Item) AND (SalesLine.“Carrier Charges” <> 0) THEN BEGIN
SalesLine.SETRANGE(“Document No.”,SalesInvLine.“Document No.”);
SalesInvLine.“Line No.” := SalesLine.“Line No.” + 10000;
SalesInvLine.Type := SalesLine.Type::“Charge (Item)”;
SalesInvLine.“No.” := ‘I-FREIGHT’;
SalesInvLine.Description := ‘Item Freight Charges’;
SalesInvLine.“Amount Including VAT” := SalesLine.“Carrier Charges”;
In this code I want to write the code for updating it in value entries also


You should NEVER insert ValueEntries “manually”. If you do, then you are doomed to get problems.
Always use the normal posting rutines.

But if you have inserted the item charge line to the sales line table (37), then when you post it, NAV will create a value entry based on that line.

I have carrier charges field in sales line and in sales order I want to post the item with item charges and that carrier charges should come as item charges

can u give me the code for it??

It is very urgent please suggest me the code

It should be updated in all entries automatically
please suggest me the code and where I have to write the code for it?

Hi again,
No I cannot show the the code, as I still have not completely understood what your problem is. It looks like you already have the code (inserting the lines in table 37). So when you post the invoice, these lines becomes value entries.


Actually my problem is when I post the item in sales order the item charges should be post in background by not selecting the charge(item) in type field of sales order as second line

Please Help me

How to insert the item charge line to the sales line table