RecordRef Value to Record

rixrixrixrix Member Posts: 121
Dear friends

-Can you please help me with this problem?
-Rec.Mn is decimal and so is Table2.Quantity
-Rec is of type Record and SrcTableRef is RecordRef

Problem: first of these lines works without problem, second one causes Navision Crash

Rec.Id := SrcTableRef.FIELD(Table2.FIELDNO("No.")).VALUE;
Rec.Mn:= SrcTableRef.FIELD(Table2.FIELDNO(Quantity)).VALUE;

(If I comment second line, all code works perfectly)

P.S. I am just testing the code ... I am gonna pass FieldNo as variable of course ....

Comments

  • BeliasBelias Member Posts: 2,998
    does srctableref and table2 refers to the same table?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • rixrixrixrix Member Posts: 121
    Yes
    All code looks like this(little bit different table names):

    OrigPredAnal.SETFILTER("Line Type",'Item');
    OrigPredAnal.SETFILTER(Month,'2006.01..2007.12');
    OrigPredAnal.SETFILTER(Quantity,'>1000');
    
    SrcTableRef.GETTABLE(OrigPredAnal);
    
    IF SrcTableRef.FINDSET(FALSE,FALSE) THEN BEGIN
            REPEAT
               IF Rec.GET(SrcTableRef.FIELD(OrigPredAnal.FIELDNO("Sum Item No.")).VALUE) THEN BEGIN
               Rec.Mnozstvo := Rec.Mnozstvo + SrcTableRef.FIELD(OrigPredAnal.FIELDNO("Quantity")).VALUE;
                Rec.MODIFY;
              END ELSE BEGIN
                Rec.INIT;
                Rec.Id := SrcTableRef.FIELD(OrigPredAnal.FIELDNO("Sum Item No.")).VALUE;
                Rec.Mnozstvo := SrcTableRef.FIELD(OrigPredAnal.FIELDNO(Quantity)).VALUE;
                Rec.INSERT;
              END;
    
            UNTIL SrcTableRef.NEXT = 0;
          END;
    
  • BeliasBelias Member Posts: 2,998
    edited 2011-01-04
    First: change this
    OrigPredAnal.SETFILTER("Line Type",'Item');
    
    to this
    OrigPredAnal.SETFILTER("Line Type",origpredanal."line type"::item);
    OrigPredAnal.SETRANGE("Line Type",origpredanal."line type"::item);
    

    Second:
    what do you mean with "navision crash"?does it errors?or it really close inexpectedly?
    if it's an error, post it...

    P.S.: i'm wondering why are you using a recref for this loop...can't you simply use origrecamount to do the repeat/until?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • rixrixrixrix Member Posts: 121
    1. SETFILTERS works perfectly, no need to change it (if I comment problematic line, everything works as expected)

    2. Yes navision just crashes with no error. Just : Unexpected error , do yo wan to send info to Microsoft .... and Client restarts

    3.
    P.S.: i'm wondering why are you using a recref for this loop...can't you simply use origrecamount to do the repeat/until?

    Because RecRef will point to different source records changing at runtime.
  • BeliasBelias Member Posts: 2,998
    1. it works, but it's just a matter of "best practice" when writing code (i should have said it). When you filter on a single value, use SETRANGE instead of SETFILTER (i corrected my previous post where i made a mistake with copy/paste) :mrgreen:
    2. sorry, i don't have time to check the code up to now
    3. you can just use another record variable, like OrigPredAnal2 :-k
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • rixrixrixrix Member Posts: 121
    PROBLEM SOLVED:

    Besided
    Rec.Mnozstvo := SrcTableRef.FIELD(OrigPredAnal.FIELDNO("Quantity")).VALUE;
    

    I have to do it like this
    FieldRefVar := SrcTableRef.FIELD(OrigPredAnal.FIELDNO("Quantity"));
    Rec.Mnozstvo := FieldRefVar.VALUE;
    
  • kinekine Member Posts: 12,562
    And using local language for naming fields is not good idea too... (Mnozstvo) - why not to use Quantity as in rest of the application? ;-) Try to keep the standards... (it will be better for maintenance and for others which will be in touch with the system).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.