Record in a report

Navi_LearnerNavi_Learner Member Posts: 356
I have a problem in retrieving a field in a report. I create a report on several tables. I create some variables, one of which is SalesCredit with data type Record.

Here is my code:
In the OnAfterGetRecord of Return Order
SalesCredit.SETFILTER("Return Order No.", "Return Order"."No.");
IF SalesCredit.FIND('-') THEN BEGIN
"Return Order"."No." := SalesCredit."Return Order No.";

END;

The Sales Credit No. in all records is PS10001 when I retrieve the report.
Does anyone why my code doesn't work? Thanks in advance!

Comments

  • awarnawarn Member Posts: 261
    Change the code:

    SalesCredit.SETFILTER("Return Order No.", "Return Order"."No.");
    IF SalesCredit.FIND('-') THEN BEGIN
    "Return Order"."No." := SalesCredit."Return Order No.";

    END ELSE BEGIN
    "Return Order"."No." := '';
    END;


    The variable "Return Order"."No." was not being reset.
  • ara3nara3n Member Posts: 9,257
    Also I would use instead of
    //old
    SalesCredit.SETFILTER("Return Order No.", "Return Order"."No.");


    //new
    SalesCredit.SETRANGE("Return Order No.", "Return Order"."No.");
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Navi_LearnerNavi_Learner Member Posts: 356
    No, it doesn't work either
  • ara3nara3n Member Posts: 9,257
    Could you tell me what you are printing on the report? what is the source expression of the textbox in body section? I would create a text varialbe instead of assigning it to ReturnOrderNo.

    here is how I would do it.

    onaftergetrecord()

    MyReturnNo := '';
    SalesCredit.setrange("Return Order No.", "Return Order"."No.");
    IF SalesCredit.FIND('-') THEN
    MyReturnNo := SalesCredit."Return Order No.";



    add to the body section a text box with sourcexp MyReturnNo.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Navi_LearnerNavi_Learner Member Posts: 356
    But why there's extra line of record displaying the first Record, Here's the output:

    Customer ID Return No.
    PS10001
    RED01 PS10001
    SUN02 PS10011
  • Navi_LearnerNavi_Learner Member Posts: 356
    But why there's extra line of record displaying the first Record, Here's the output:

    Customer ID Return No.
    PS10001
    RED01 PS10001
    SUN02 PS10011
  • ara3nara3n Member Posts: 9,257
    You might have a customer with customer no. Blank?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Navi_LearnerNavi_Learner Member Posts: 356
    :D SOlVED! Thanks! Regarding the same report, I create another two variables with Date type RECORD. One is CreditLineTable which is Sales Cr. Memo Line and the other one is CreditTable which is Sales Cr. Memo Header and the other two variables: CreditItem and CreditQuantity. I want to retrieve the Item and quantity from Sales Cr. Memo Line. I make full use of the code you sent to me before. Here is the code:
    CreditItem :='' ;
    CreditLineTable.SETFILTER("Document No.", SalesCreditTable."No.");
    IF CreditLineTable.FIND('-') THEN BEGIN
    CreditItem := CreditLineTable."No." ;
    END;
    CreditQuantity := 0 ;
    CreditLineTable.SETFILTER("Document No.", SalesCreditTable."No.");
    IF CreditLineTable.FIND('-') THEN BEGIN
    CreditItem := CreditLineTable."Quantity." ;
    END;


    The First record just get one item and the rest of the records are repeated one item from the other record. Can you expert point it out? Thanks!
  • ara3nara3n Member Posts: 9,257
    you code can be run this way as well.
    CreditItem :='' ;
    CreditQuantity := 0 ;
    CreditLineTable.SETRANGE("Document No.", SalesCreditTable."No.");
    IF CreditLineTable.FIND('-') THEN BEGIN
    CreditItem := CreditLineTable."No." ;
    CreditItem := CreditLineTable."Quantity." ;
    END;

    I don't understand what you are looking for. there could be many sales credit line for a credit memo header. Do you want to print all the items? If yes then, you need to have two dataitems

    Sales Cr. Header
    -->Sales Cr. Line

    Link them and in body section display the appropriete fields
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Navi_LearnerNavi_Learner Member Posts: 356
    Thanks! Actually I create a report based on Return Header and Return line tables which I recently created. I can connect either return Header or Return Line with Sales Cr. Memo Header as they all have RA#, but in Sales Cr. Memo Line I can't retrieve any data since there's no relationship between Return Header or Return line, but Credit No links Sales Cr. Memo Header together with Sales Cr. Memo Line. That's why I create the two variables with record data type. I need my report like this:
    RA# Return Item Return Quantity
    R10001 AC01 10
    R10002 SD03 15
    What's the problem of my code? Do I have to write something about Return Header to link the data? Thanks
  • krikikriki Member, Moderator Posts: 9,118
    ara3n wrote:
    Also I would use instead of
    //old
    SalesCredit.SETFILTER("Return Order No.", "Return Order"."No.");


    //new
    SalesCredit.SETRANGE("Return Order No.", "Return Order"."No.");
    Remember this one: use SETFILTER ONLY if you can't use SETRANGE. SETRANGE has the potential to be faster then SETFILTER.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.