Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Date Compare custom object 5.5 SP2

ChiragShah
Contributor II

Hi All,

 

We have a custom object in Archer 5.4 which compares start and end date. If the end date selected by the user is less than (before) start date it will give warning message and not allow to save or apply the record.

 

Post upgrade to Archer 5.5 SP2 the functionality is not working.

 

It will restrict the user form save or apply the record is end date if less than start sate but will not give warning message (pop up box).

Have attached the querry used in 5.4 below. Any help will be highly appreciated.

 

Regards,

Chirag.

 

<script type="text/javascript">   
var startDate = 4507, startDateValue;   
var endDate = 14721, endDateValue;   
var messageBoxText = "Please select a valid end date. End date cannot be before Start date";   
var messageBoxTitle = 'Warning';   
var daysToCompare = -1;
Sys.Application.add_load(function() {   
   // Hijack Save/Apply Buttons   
   $('#master_btnSave').attr('href',"#").removeAttr("onclick").unbind("click").click(function(){ DateCheck

('save');return false;});   
   $('#master_btnSave > div > div > img').removeAttr('onclick').unbind("click");   
   $('#master_btnApply').attr('href',"#").removeAttr('onclick').unbind("click").click(function(){ DateCheck

('apply');return false;});   
   $('#master_btnApply > div > div > img').removeAttr('onclick').unbind("click");   
});
function DateCheck(type) {   
   //Get Date Values   
startDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(startDate, false)));
endDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(endDate, false)));   
   if(startDateValue && endDateValue) {   
    if(daydiff(parseDate(startDateValue), parseDate(endDateValue)) <= daysToCompare) {   
      WarningAlert(messageBoxText,'',messageBoxTitle);   
    } else {   
      SaveApply(type)   
    }   
   } else {   
    SaveApply(type)   
   }   

function SaveApply(type) {   
   if (type == 'save') {   
    ShowAnimationAndPostback('master$btnSave');   
   } else if (type == 'apply') {   
    ShowAnimationAndPostback('master$btnApply');   
   }   

function parseDate(str) {   
   str = str.getMonth()+1 + '/' + str.getDate() + '/' + str.getYear();   
   var mdy = str.split('/')   
   return new Date(mdy[2], mdy[0]-1, mdy[1]);   

function daydiff(first, second) {   
   return (second-first)/(1000*60*60*24)   
}
</script>

57 REPLIES 57

I take it that fields are on the layout?  The custom object was build with the idea that the fields are editable by the user, is that still the case?

 

If both questions above are yes, here's an update script that has debugging information outputted to the console.  Post what's displayed in the console upon running.

 

<script type="text/javascript">
      var weaknessWeaknessStartDate = 22883, weaknessWeaknessStartDateValue;
      var weaknessScheduledDate = 22884, weaknessScheduledDateValue;
      var messageBoxText = "Please select a valid end date. End date cannot be before Start date";
      var messageBoxTitle = 'Warning';
      var daysToCompare = -1;
      var oldApplyClick, oldSaveClick

     Sys.Application.add_load(function() {
           // Hijack Save/Apply Buttons
           if (oldApplyClick == undefined) oldApplyClick = $("#master_btnApply").attr('onclick');
           if (oldSaveClick == undefined) oldSaveClick = $("#master_btnSave").attr('onclick');
           $('#master_btnSave').removeAttr('onclick').click(function(){ DateCheck('save');return false;});
           $('#master_btnApply').removeAttr('onclick').click(function(){ DateCheck('apply');return false;});
      });

     function DateCheck(type) {
           //Get Date Values
           weaknessStartDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(weaknessStartDate, false)));
           weaknessScheduledDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(weaknessScheduledDate, false)));
           console.log('Weakness Start Date Value ' + weaknessStartDateValue);
           console.log('Weakness Schedule Date Value ' + weaknessScheduledDateValue);
           if(weaknessStartDateValue && weaknessScheduledDateValue) {
                if(daydiff(parseDate(weaknessStartDateValue), parseDate(weaknessScheduledDateValue)) <= daysToCompare) {
                     WarningAlert(messageBoxText,'',messageBoxTitle);
                } else {
                     SaveApply(type)
                }
           } else {
                SaveApply(type)
           }
      }

     function SaveApply(action) {
           if (action == 'save') {
                return oldSaveClick();
           } else if (action == 'apply') {
                return oldApplyClick();
           }
      }

     function parseDate(str) {
           str = str.getMonth()+1 + '/' + str.getDate() + '/' + str.getYear();
           var mdy = str.split('/')
           return new Date(mdy[2], mdy[0]-1, mdy[1]);
      }

     function daydiff(first, second) {
           return (second-first)/(1000*60*60*24)
      }
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Advisory Consultant

The warning box is in the code so it will show if the conditions match.  I posted an update code yesterday that output the dates in the browser console window.  Run that and see what dates are coming back.

 Advisory Consultant

yes I see it in the console. So here's what we need. The user input information into our app, we need an alert box to pop up whether saving or applying, if the start date is after the schedule date. The alert box is not popping up. Of course I'm doing it in my Dev so I've create fake records with start date after the scheduled date and no pop up box is coming up.

On line 24 above it looking a the number of days between the Start date and the Schedule Date and seeing if it less then or equal to what the daysToCompare variable.

 

What you can do is replace that line with,

if(weaknessStartDateValue >= weaknessScheduledDateValue) {

 Advisory Consultant

So this is what I have and it's still not giving me the alert box. It can be equal to the scheduled date It just can be after the schedule date.

 

Thanks for all that you can help with.

 

 

<script type="text/javascript">
      var weaknessStartDate = 22883, weaknessStartDateValue;
      var weaknessScheduledDate = 22884, weaknessScheduledDateValue;
      var messageBoxText = "Please select a valid end date. End date cannot be before Start date";
      var messageBoxTitle = 'Warning';
      var daysToCompare = -1;
      var oldApplyClick, oldSaveClick;

     Sys.Application.add_load(function() {
           // Hijack Save/Apply Buttons
           if (oldApplyClick == undefined) oldApplyClick = $("#master_btnApply").attr('onclick');
           if (oldSaveClick == undefined) oldSaveClick = $("#master_btnSave").attr('onclick');
           $('#master_btnSave').removeAttr('onclick').click(function(){ DateCheck('save');return false;});
           $('#master_btnApply').removeAttr('onclick').click(function(){ DateCheck('apply');return false;});
      });

     function DateCheck(type) {
           //Get Date Values
           weaknessStartDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(weaknessStartDate, false)));
           weaknessScheduledDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(weaknessScheduledDate, false)));
           console.log('Weakness Start Date Value ' + weaknessStartDateValue);
           console.log('Weakness Schedule Date Value ' + weaknessScheduledDateValue);
           if(weaknessStartDateValue > weaknessScheduledDateValue) {
                if(daydiff(parseDate(weaknessStartDateValue), parseDate(weaknessScheduledDateValue)) <= daysToCompare) {
                     WarningAlert(messageBoxText,'',messageBoxTitle);
                } else {
                     SaveApply(type)
                }
           } else {
                SaveApply(type)
           }
      }

     function SaveApply(action) {
           if (action == 'save') {
                return oldSaveClick();
           } else if (action == 'apply') {
                return oldApplyClick();
           }
      }

     function parseDate(str) {
           str = str.getMonth()+1 + '/' + str.getDate() + '/' + str.getYear();
           var mdy = str.split('/');
           return new Date(mdy[2], mdy[0]-1, mdy[1]);
      }

     function daydiff(first, second) {
           return (second-first)/(1000*60*60*24);
      }
</script>

 

Tiara you replaced the wrong line  

 

Here's the correct update

<script type="text/javascript">
      var weaknessWeaknessStartDate = 22883, weaknessWeaknessStartDateValue;
      var weaknessScheduledDate = 22884, weaknessScheduledDateValue;
      var messageBoxText = "Please select a valid end date. End date cannot be before Start date";
      var messageBoxTitle = 'Warning';
      var daysToCompare = -1;
      var oldApplyClick, oldSaveClick

      Sys.Application.add_load(function() {
           // Hijack Save/Apply Buttons
           if (oldApplyClick == undefined) oldApplyClick = $("#master_btnApply").attr('onclick');
           if (oldSaveClick == undefined) oldSaveClick = $("#master_btnSave").attr('onclick');
           $('#master_btnSave').removeAttr('onclick').click(function(){ DateCheck('save');return false;});
           $('#master_btnApply').removeAttr('onclick').click(function(){ DateCheck('apply');return false;});
      });

     function DateCheck(type) {
           //Get Date Values
           weaknessStartDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(weaknessStartDate, false)));
           weaknessScheduledDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(weaknessScheduledDate, false)));
           console.log('Weakness Start Date Value ' + weaknessStartDateValue);
           console.log('Weakness Schedule Date Value ' + weaknessScheduledDateValue);
           if(weaknessStartDateValue && weaknessScheduledDateValue) {
                //if(daydiff(parseDate(weaknessStartDateValue), parseDate(weaknessScheduledDateValue)) <= daysToCompare) {
                if(weaknessStartDateValue > weaknessScheduledDateValue) {
                    WarningAlert(messageBoxText,'',messageBoxTitle);
                } else {
                     SaveApply(type)
                }
           } else {
                SaveApply(type)
           }
      }

     function SaveApply(action) {
           if (action == 'save') {
                return oldSaveClick();
           } else if (action == 'apply') {
                return oldApplyClick();
           }
      }

     function parseDate(str) {
           str = str.getMonth()+1 + '/' + str.getDate() + '/' + str.getYear();
           var mdy = str.split('/')
           return new Date(mdy[2], mdy[0]-1, mdy[1]);
      }

     function daydiff(first, second) {
           return (second-first)/(1000*60*60*24)
      }
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Advisory Consultant

still a no go. Like before I see it in the console. but I need the users to see the alert box.  

This line (25), if(weaknessStartDateValue > weaknessScheduledDateValue) { isn't evaluating as true.

 

Can you post what's in the console so I can see the values?  Otherwise I'm not sure what's going on.

 

Try adding this line above line 25 and see what the evaluation is

console.log(weaknessStartDateValue > weaknessScheduledDateValue);

 Advisory Consultant

David, I'm not sure what version this is happening on, but could it be an issue with WarningAlert? Maybe try replacing 'WarningAlert' with 'Alert' and see what happens?

 

*I haven't tested either of the two scripts in any archer environment, I'm just shooting from the hip*

Thanks Sam, the WarningAlert is an Archer function to display a dialog box; fitting with Archer UI to the user. Though looking at that function call, it seems that I've got the parameters wrong for the call. Tiara hasn't reported any errors being reported in the browsers console since she first reported about an error in radwindowscript.js.  Since then we've changed the way the script is checking the dates and it's not getting to that line.

 

Tiara replace (line 27), WarningAlert(messageBoxText,'',messageBoxTitle); with WarningAlert(messageBoxText,messageBoxTitle);

 Advisory Consultant