GETRANGEMAX -

nav_studentnav_student Member Posts: 175
Hello

i´m analising the codeunit - 230 GenJnlManagement, on the function Lookup.

I see this code:
COMMIT;
 GenJnlBatch."Journal Template Name" := GenJnlLine.GETRANGEMAX("Journal Template Name");
GenJnlBatch.Name := GenJnlLine.GETRANGEMAX("Journal Batch Name");
 GenJnlBatch.FILTERGROUP := 2;
GenJnlBatch.SETRANGE("Journal Template Name",GenJnlBatch."Journal Template Name");
 GenJnlBatch.FILTERGROUP := 0;
 
IF FORM.RUNMODAL(0,GenJnlBatch) = ACTION::LookupOK THEN BEGIN
  CurrentJnlBatchName := GenJnlBatch.Name;
  SetName(CurrentJnlBatchName,GenJnlLine);
END;

The GETRANGEMAX is getting the maximum value for the field ( Journal Template Name), but what is the criteria from this command to get the maximum value?

Thanks for your answers.


Best Regards.

Comments

  • matttraxmatttrax Member Posts: 2,309
    GETRANGEMAX returns the maximum possible value from the filtered set...that is what you filtered on.

    So with SETRANGE(Var, 1, 5) the GETRANGEMAX command will always return 5.
  • nav_studentnav_student Member Posts: 175
    Yes i understand that but what in this case "Journal Template Name" ( it´s a CODE) what is the criteria to return the maximum value?

    GenJnlBatch."Journal Template Name" := GenJnlLine.GETRANGEMAX("Journal Template Name");
  • matttraxmatttrax Member Posts: 2,309
    The journal line is passed by reference in that function, meaning all of the filters are passed with it. Perhaps a FIND is not done before the function call and the parameter does not yet (or ever) refer to an actual record. The only way to get a possible value of the field would be to use GETRANGEMIN or GETRANGEMAX.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Yes i understand that but what in this case "Journal Template Name" (it´s a CODE) what is the criteria to return the maximum value?

    Same approach:

    SETRANGE("Journal Template Name", 'AAA);
    GETRANGEMAX("Journal Template Name") -> 'AAA'

    SETRANGE("Journal Template Name", 'AAA,'ZZZ')
    GETRANGEMAX("Journal Template Name") -> 'ZZZ'

    SETRANGE("Journal Template Name", 'ZZZ', 'AAA')
    GETRANGEMAX("Journal Template Name") -> 'AAA'

    It has nothing to do with field values existing in the underlying table, or sorting order. It just returns 'upper' value of range FILTER set on the field.

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.