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

Can you give more details on, not working?  One thing to check is, are you getting any JavaScript errors in the browser console?

 Advisory Consultant

Hi David,

 

I am using below code and using 6.5 version, when i see i just see pop message and record get saved with wrong details.

 

Start date as 3/1/2019  and end date is 12/12/2018 which is less than start date but i am getting pop up and record getting saved. do i need to cahange anything in below code. 

 

Thanks in advance.

<script type="text/javascript">
var startDate = 30946, startDateValue;
var endDate = 30947, 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>

Kulk, take a look at my post here in regards to using a new way of hijacking the Save and Save and Close buttons here, https://community.rsa.com/thread/133011#comment-915535 

 

Give that a shot and see.

 Advisory Consultant

David,

Do you have an update version for 6.6 /6.6?

 

Thanks,

Hi David,

 

I tried using this code for 6.7 but its not working not showing any popup or error. could you pls help ?

Hi Tiara, 

Did you get the solution to this because I am getting the same error? but in 6.7

venubabuchirum2
Contributor III

Hi David, @DavidPetty @SK_Archer 

do you have this script for 6.7 or above ?

Hi David, 

I wanted to implement this custom code for our environment in ARCHER 6.13 P2 but it is not working for me. Could you please let me know what changes should I make so that this code work in version 6.13 P2?

Thank you in advance