TextBox to act as Standard NAV date Filter

gulamdastagirgulamdastagir Member Posts: 411
i have a textbox with source expression as varText.

But it does not support validation and when i type 'T' for today etc so how to get the functionality?
Regards,

GD

Comments

  • SavatageSavatage Member Posts: 7,142
    why make it text type if it's really a date type?

    you can make it a date type & convert to text when needed if you like.
  • gulamdastagirgulamdastagir Member Posts: 411
    actually i want to filter a Range 010101..080808 and only one text box but i guess i have to take two textboxes with variables of type Date

    thanks savatage
    Regards,

    GD
  • jreynoldsjreynolds Member Posts: 175
    In the OnAfterInput trigger for your text box you can call the MakeDateText function in codeunit 1. Pass it the Text parameter that comes with this trigger.
  • NaviDevNaviDev Member Posts: 365
    Here how is my tip and trick works for this.

    1. Declare a record variable that has a field datatype Date in it. Lets say we use the Date record as variable recDate.
    2. Declare a text variable for your TextBox to act as Standard NAV date Filter. Lets use myTextDate.
    3. Put myTextDate on the SourceExpr property of your textbox.
    4. On the validate trigger of your textbox. Put the code like this.
    recDate.SETFILTER("Period Start", myTextDate);
    myTextDate := recDate.GETFILTER("Period Start");
    

    5. Done.

    Note : If you input the character listed below in the textbox:

    M = Will return the date of Monday in the current week.
    T = Will return the date of Tuesday in the current week.
    W = Will return the date of Wednesday in the current week.
    TH = Will return the date of Tuesday in the current week.
    F = Will return the date of Friday in the current week.
    S = Will return the date of Saturday in the current week.
    SU = Will return the date of Sunday in the current week.

    If you want to capture the character 'T' as today or 'W' as workdate then you must have a LONG code like this.
    myTextDate := UPPERCASE(myTextDate);
    
    //---- Make TU as Tuesday
    IF STRPOS(myTextDate, 'TU') > 0 THEN BEGIN
      recDate.SETFILTER("Period Start", 'T');
      IF STRLEN(myTextDate) <> 2 THEN BEGIN
        WHILE STRPOS(myTextDate, 'TU') <> 0 DO BEGIN
          myTextDate := COPYSTR(myTextDate, 1, STRPOS(myTextDate, 'TU') - 1) +
             recDate.GETFILTER("Period Start") +
             COPYSTR(myTextDate, STRPOS(myTextDate, 'TU') + 2, STRLEN(myTextDate));
        END;
      END ELSE
        myTextDate := recDate.GETFILTER("Period Start");
    END;
    
    //---- Make WE as Wednesday
    IF STRPOS(myTextDate, 'WE') > 0 THEN BEGIN
      recDate.SETFILTER("Period Start", 'W');
      IF STRLEN(myTextDate) <> 2 THEN BEGIN
        WHILE STRPOS(myTextDate, 'WE') <> 0 DO BEGIN
          myTextDate := COPYSTR(myTextDate, 1, STRPOS(myTextDate, 'WE') - 1) +
             recDate.GETFILTER("Period Start") +
             COPYSTR(myTextDate, STRPOS(myTextDate, 'WE') + 2, STRLEN(myTextDate));
        END;
      END ELSE
        myTextDate := recDate.GETFILTER("Period Start");
    END;
    
    
    //---- for the character T as TODAY
    IF STRPOS(myTextDate, 'T') > 0 THEN BEGIN
      IF STRLEN(myTextDate) <> 1 THEN BEGIN
        WHILE STRPOS(myTextDate, 'T') <> 0 DO BEGIN
          myTextDate := COPYSTR(myTextDate, 1, STRPOS(myTextDate, 'T') - 1) +
             FORMAT(TODAY) +
             COPYSTR(myTextDate, STRPOS(myTextDate, 'T') + 1, STRLEN(myTextDate));
        END;
      END ELSE
         myTextDate := FORMAT(TODAY);
    END;
    
    //---- for the character W as WORKDATE
    IF STRPOS(myTextDate, 'W') > 0 THEN BEGIN
      IF STRLEN(myTextDate) <> 1 THEN BEGIN
        WHILE STRPOS(myTextDate, 'W') <> 0 DO BEGIN
          myTextDate := COPYSTR(myTextDate, 1, STRPOS(myTextDate, 'W') - 1) +
             FORMAT(WORKDATE) +
             COPYSTR(myTextDate, STRPOS(myTextDate, 'W') + 1, STRLEN(myTextDate));
        END;
      END ELSE
         myTextDate := FORMAT(WORKDATE);
    END;
    
    recDate.SETFILTER("Period Start", myTextDate);
    myTextDate := recDate.GETFILTER("Period Start");
    

    Hope this works for you too :D
    Navision noob....
  • djangodjango Member Posts: 9
    Thanks to jreynolds for his post that got me going in the right direction. I have a report where I have a text box on the options tab, and I want that text box to work as a date and recieve date ranges and values such as "t", "y-1", etc. Instead of using MakeDateText, I found MakeDateFilter in Codeunit1. It works!
Sign In or Register to comment.