What wrong with the code

mkpjsrmkpjsr Member Posts: 587
Hi all,
I am trying to fetch the line amount of sales line having Item Charges, so i have written the following code but its giving value 0. I have written the code under Integer OnPreSection trigger
globals i have used:
SalesInvoiceLine->Rec->Sales Invoice Line
FCharges->Decimal

//'FORWARDING CHARGES' :- A Item Charges No. i have created

IF SalesInvoiceLine.FIND('-') THEN
BEGIN
IF SalesInvoiceLine."No."='FORWARDING CHARGES' THEN
BEGIN
//SalesInvoiceLine.CALCFIELDS("Line Amount");
FCharges:=SalesInvoiceLine."Line Amount";
END;
END;

If i am removing the comment from the fifth line its fetching the line amount of the first line. Actually i want to fetch the line amount of the line having item no as 'FORWARDING CHARGES'

Can anubody tell me whats the problem.

Comments

  • matttraxmatttrax Member Posts: 2,309
    You have to loop through the record set that is returned by the FIND using a REPEAT..UNTIL. You could also try doing a CALCSUMS if the current key supports it.

    And you really shouldn't hard code the No. field in the code like that.
  • ssinglassingla Member Posts: 2,973
    matttrax wrote:
    You have to loop through the record set that is returned by the FIND using a REPEAT..UNTIL. You could also try doing a CALCSUMS if the current key supports it.

    And you really shouldn't hard code the No. field in the code like that.

    Further move the code to "OnAfterGetRecord" rather than OnPreSection
    CA Sandeep Singla
    http://ssdynamics.co.in
  • mkpjsrmkpjsr Member Posts: 587
    matttrax wrote:
    You have to loop through the record set that is returned by the FIND using a REPEAT..UNTIL. You could also try doing a CALCSUMS if the current key supports it.

    And you really shouldn't hard code the No. field in the code like that.

    if i am using a loop then its causing another problem as some sections are not properly displayed
  • ssinglassingla Member Posts: 2,973
    Have you used setrange/setfilter for type = Charge (Item). Further apply filter for your "Forwarding Charges" for field "No." and then try.
    CA Sandeep Singla
    http://ssdynamics.co.in
  • matttraxmatttrax Member Posts: 2,309
    Yeah, didn't realize this was on a report. You'll need to properly set your filters. The report will handle the looping for you.
  • mkpjsrmkpjsr Member Posts: 587
    matttrax wrote:
    Yeah, didn't realize this was on a report. You'll need to properly set your filters. The report will handle the looping for you.

    i have tried this code but its not working


    SalesInvoiceLine.RESET;
    //SalesInvoiceLine.SETRANGE(SalesInvoiceLine."Document No.","Sales Invoice Header"."No.");
    SalesInvoiceLine.SETRANGE(SalesInvoiceLine.Type,SalesInvoiceLine.Type::"Charge (Item)");
    SalesInvoiceLine.SETFILTER(SalesInvoiceLine."No.",'FORWARDING CHARGES');
    CCharges:=SalesInvoiceLine."Line Amount";

    still its giving line amount from 1st line.
  • ssinglassingla Member Posts: 2,973
    Where is Find('-') or Findset?
    CA Sandeep Singla
    http://ssdynamics.co.in
  • mkpjsrmkpjsr Member Posts: 587
    ssingla wrote:
    Where is Find('-') or Findset?


    SalesInvoiceLine.RESET;
    //SalesInvoiceLine.SETRANGE(SalesInvoiceLine."Document No.","Sales Invoice Header"."No.");
    SalesInvoiceLine.SETRANGE(SalesInvoiceLine.Type,SalesInvoiceLine.Type::"Charge (Item)");
    SalesInvoiceLine.SETFILTER(SalesInvoiceLine."No.",'FORWARDING CHARGES');
    IF SalesInvoiceLine.FIND('-') THEN
    begin
    CCharges:=SalesInvoiceLine."Line Amount";
    end;

    if i am writing this, still the result is same
  • idiotidiot Member Posts: 651
    mkpjsr wrote:
    ssingla wrote:
    Where is Find('-') or Findset?


    SalesInvoiceLine.RESET;
    //SalesInvoiceLine.SETRANGE(SalesInvoiceLine."Document No.","Sales Invoice Header"."No.");
    SalesInvoiceLine.SETRANGE(SalesInvoiceLine.Type,SalesInvoiceLine.Type::"Charge (Item)");
    SalesInvoiceLine.SETFILTER(SalesInvoiceLine."No.",'FORWARDING CHARGES');
    IF SalesInvoiceLine.FIND('-') THEN
    begin
    CCharges:=SalesInvoiceLine."Line Amount";
    end;

    if i am writing this, still the result is same


    matttrax wrote:
    You have to loop through the record set that is returned by the FIND using a REPEAT..UNTIL.
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • mkpjsrmkpjsr Member Posts: 587
    idiot wrote:
    mkpjsr wrote:
    ssingla wrote:
    Where is Find('-') or Findset?


    SalesInvoiceLine.RESET;
    //SalesInvoiceLine.SETRANGE(SalesInvoiceLine."Document No.","Sales Invoice Header"."No.");
    SalesInvoiceLine.SETRANGE(SalesInvoiceLine.Type,SalesInvoiceLine.Type::"Charge (Item)");
    SalesInvoiceLine.SETFILTER(SalesInvoiceLine."No.",'FORWARDING CHARGES');
    IF SalesInvoiceLine.FIND('-') THEN
    begin
    CCharges:=SalesInvoiceLine."Line Amount";
    end;

    if i am writing this, still the result is same


    matttrax wrote:
    You have to loop through the record set that is returned by the FIND using a REPEAT..UNTIL.


    Actually i am using this code on report so if i am using loop then file i am getting the records but some sections of the reports are not getting displayed. Can u plz suggest some solution.
Sign In or Register to comment.