Skip to main content

How to Use javascript Function for Default Date Value

Followed by 3 people

Comments

1 comment

  • Sean Krause

    Worked out solution:

    1. Added a JavaScript file to the application called "CustomDateFunctions.js"

    2. Added a getMostRecentJuly1st function to the CustomDateFunctions.js file

    function getMostRecentJuly1st() {

      var today = new Date();
      var currentYear = today.getFullYear();

      // Create a date for July 1st of the current year
      var july1st = new Date(currentYear, 6, 1); // Month is 6 because January is 0

        // If today's date is before July 1st, use last year's July 1st

      if (today < july1st) {
          july1st = new Date(currentYear - 1, 6, 1);
      }

    var year = july1st.getFullYear();
    var formattedDate = '07/01/' + year;

      return formattedDate;
    }

    3. Added a "Formula Script File" element to the report and populated the Script File value with "CustomDateFunctions.js" (file added above)

    4.  I was then able to reference the getMostRecentJuly1st() function to set the default value in the date input element:


    0

Please sign in to leave a comment.