Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Jelly -->
- </style>
- <g:ui_form>
- <!-- Note the var="jvar_future_date" -->
- <g2:evaluate var="jvar_future_date">
- var max_days = gs.getProperty('max.days.defer.vul'); //Optional get from sys_proprities
- var gdt = new GlideDateTime();
- gdt.getLocalDate();
- //gdt.addYearsLocalTime(1)
- //gdt.addDaysLocalTime(90);
- gdt.addDaysLocalTime(max_days);
- gdt.getDisplayValueInternal();
- </g2:evaluate>
- <!-- Lets pass then number of days for the error message -->
- <g2:evaluate var="jvar_max_days">
- var maxx_days = gs.getProperty('max.days.defer.vul');
- maxx_days;
- </g2:evaluate>
- <!-- Insert the value of jvar_future_date" into the page -->
- <input type="hidden" id="future_date" name='future_date' value="$[jvar_future_date]" />
- <!-- Pass the number of days for the error message -->
- <input type="hidden" id="max_days" name='max_days' value="$[jvar_max_days]" />
- <!-- Attach the JavaScript Function to the onchange event -->
- <g:ui_date_time name="date" id="date" class="form-control" onchange="verifyDate()"/>
- <!-- end Jelly -->
- //start Client Script / Javascript
- function verifyDate() {
- $j('#bulk_error_messages').click(function(e){removeErrorMessage(e);});
- var maxDays = jQuery('#max_days').val();
- var providedDate = jQuery('#date').val();//Get Value Set
- var futureDate = jQuery('#future_date').val();//Get from input/hidden data
- // can not exceed one yr in the future
- if (providedDate > futureDate) {
- jQuery('#date').val(futureDate);
- var msg2 = getMessage('Exception duration may not exceed ' + maxDays + ' days. Setting Until Date to match.');
- showErrorMessage(msg2);
- return false;
- }
- }
- //********************************************************************************************************
- //Does *NOT* work in IE
- //UI Page: 'review_request'
- //Modify HTML to implement -- 'checkDate()'
- //<g:ui_date_time name="date" id="date" class="form-control" onChange="checkDate()"/>
- //v2 to-do Pass the number of days from a sys_property to UI page to Client script
- // called in html: onchange="checkDate()"
- function checkDate(){
- var today = new Date(); //Todays Date
- var maxDays = addDays(today, 90); //Set the date in the future
- //Requested Date
- //var varDate = document.getElementById("date").value; //2019-08-07 14:20:53
- var reqDate = gel('date').value; //String
- var dateRequested = Date.parse(reqDate); //Turn String into a Date Type
- var results = CompareDate(dateRequested, maxDays);
- //alert("wtf " + reqDate);
- if(results == 2 ){
- //alert("Go ahead!");
- removeErrorMessage(false);
- }else{
- //alert("NOPE!");
- showErrorMessage("The date must be less then 90 Days from now.");
- //document.getElementById("date").value = "";
- gel('date').value = '';
- }
- }
- function addDays(date, days) {
- /* Testing
- var date = new Date();
- var newDate = addDays(date, 10);
- */
- var copy = new Date(Number(date));
- copy.setDate(date.getDate() + days);
- return copy;
- }
- function CompareDate(firstDate, SecondDate) {
- /* Testing
- var date = new Date();
- var newDate = addDays(date, 10);
- CompareDate(newDate, date);
- */
- var dateOne = firstDate;
- var dateTwo = SecondDate;
- if (dateOne > dateTwo) {
- //alert("Date One is greater than Date Two.");
- return 1;
- }else if(dateOne === dateTwo) {
- //alert("Date one and two are the same.");
- return 0;
- } else{
- //alert("Date Two is greater than Date One.");
- return 2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement