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>

1 ACCEPTED SOLUTION

Accepted Solutions

DavidPetty
Archer Employee
Archer Employee

With the navigate way functionality added to 5.5 SP2 custom objects that hijack the Save and Apply actions no longer work the way they did in earlier versions and slight tweak is needed.

 

See if the updated code below works for you.

 

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

  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

       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(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 - Archer, an RSA Business

View solution in original post

56 REPLIES 56

DavidPetty
Archer Employee
Archer Employee

With the navigate way functionality added to 5.5 SP2 custom objects that hijack the Save and Apply actions no longer work the way they did in earlier versions and slight tweak is needed.

 

See if the updated code below works for you.

 

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

  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

       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(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 - Archer, an RSA Business

Hi David, Thank you for the updated script. It works


It does give us popup in google crome but does not give pop up in IE9 compatible mode. The popup worked in IE9.

 

Regards

Chirag

Hi David,

 

The script doesn't work if startdate field is a calculated field. How should i update the script?

 

Thank you in advance.

For the startDateValue try,

$('span[id$="f' + startDate+ '"]').text().trim();

 Advisory Consultant - Archer, an RSA Business

Hi David,

 

The snippet didn't work

 

var startDate = 7603, startDateValue;

 

startDateValue = $('span[id$="f' + startDate+ '"]').text().trim();

 

The element of calculated field:

<span id="master_DefaultContent_rts_s4375_f7603c">12.10.2016</span>

Forgot to change the selector.  $ = end with.  Should be * = contains.

$('span[id*="f' + startDate+ '"]').text().trim();

 Advisory Consultant - Archer, an RSA Business

Thank you David. It worked.

jsol5
Advocate II

David,

I wanted to add a warningalert in all cases.  However, if you are allowing the saveapply action, the script continues to process and despite the user not clicking "OK" on the alert, the record continues to save or apply (depending on the button you clicked).  Any ideas if it's possible to "pause" the scripts so that the user can read the warningalert and click ok before it continues to save?

Hi Jason,

you can try something like this:

function saveAndSubmit() {
  var userConfirmed=function(arg){
    if(arg) {
      changeValue(nextStatusField, valueId_02_QA_Outstanding);
      saveAndCloseCore();
    }
  };
  WarningConfirm(textConfirm_SaveAndSubmit,userConfirmed,textConfirmTitle_SaveAndSubmit);
}

function saveAndCloseCore() {
  $('#master_btnSave').click();
}