Important Update: Community URLs redirect issues are partially resolved. 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

Hello David,

 

thank you very much for this updated version. We would like to use it replace our current version.

 

We found a small issue, related to a Multi Reference Display Control field on the Layout.

The warning is shown multiple times.

I attached a screenshot of my layout, if you would like to have a package, I can provide one.

 

2017-01-10 09_57_33-XYZ Company EMS - Internet Explorer.png

I created two date fields, one cross reference and one MRDC field.

I tried to save a new record with a pair of non-vailed dates, the warning is shown. I have to press multiple times on the "OK"-button to remove the warning.

 

Could you please help us to create a updated version of the script?

 

Kind regards,

Daniel

Anonymous
Not applicable

So, what is the trick to make this work in a questionnaire then?  I assumed it was merely updating the values of the apply and save buttons...  But all I keep getting is an error: SCRIPT1004: Expected ';'

 

We are successfully using the code from David on a normal form, so I'm mostly confident that the syntax should have been fine....

Hi David Petty,

So I tried to use your custom object and it didn't work. So I'm trying to do the exact samething. but I'm using 5.5SP4. are there any changes that need to be done with different SP?

Here is my code if that helps you id where my problem is at. It is pretty much the same I just change the field names and the IDs but it seems like it's not even seeing the IDs:

 

<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)));

     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>

Nothing should have to be changed other then the field id's Tiara.  If you open the browsers developer tools/console are you getting any JavaScript errors?

 Advisory Consultant

I don't get an error in my script.

I am getting an error in radwindowscript.js. it references the border width.

Ok, so that's good.  It's possible that the field id's are incorrect or is the custom object in a questionnaire?

 Advisory Consultant

Nope not a questionnaire. I checked the ids several times because I thought the same thing.

That shouldn't cause any issues being that .js file isn't being used by the custom object.

 Advisory Consultant

ok so I'm not getting the pop up box when I hit save but it knows my dates are wrong because it won't let me save or apply. I need the pop up boxes not sure what I'm missing. Is it a  function to call the pop up box that's missing in my script?