Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Date Comparison in Archer 6.3

UmaKrisVenkat
Contributor II

We have this Date Comparison JavaScript in Archer 5.5 running, but we are unable to get this script to work in Archer 6.3 P4.

I am attaching the copy of the current JavaScript that is being used and is working in Archer 5.5.

 

Please help us resolve this issue! 

14 REPLIES 14

FilipeVieira2
Contributor

So, the code works fine with save button, but, i need that works with a AWF Transition node button. is it possible ? I made the test and didn't work with it =/ 

Just override AWF button handler. You can find the button ID by clicking Inspect Element and going to Developers Tools.

Hi David David Petty

This approach is working fine for hijacking Save and Apply buttons with 1 caveat.

When user enters wrong dates , clicks on Apply( Save&Close) he gets custom warning alert ("Please select a valid end date......" ).

But if he chooses to ignore that alert and try to close the record by clicking X,  it does not show "Unsaved Changes" warning alert. Somehow it is clearing the dirty record.  Can you suggest to fix to get this "unsaved changes" alert too? 

We need to implement similar solution at our end but this is causing loss of warning functionality.

Hi.  I was going to adopt this Script to my use case, and I thought I would ask first:

 

Do you have a suggestion on the most efficient way to handle this type of validation on multiple fields (perhaps building an array and running a for each loop)?

 

For example:

Start of Planning < Start of Fieldwork < Fieldwork Completion < Wrap-Up Completion < Draft Report < Final Report

 

(to validate that these dates were chronologically rational if the field was populated.)

 

I was staring at the code thinking "how could I compare all of these sets of data the right way and not make an embarrassing example of JavaScript (for which I am an amateur)".  I got this far.  Thoughts?  I just realized it does not validate dates if a pair is skipped:

 

My arrays of objects for example: 

a,b,c,d,e

b,c,d,e,f

 

It works fine to compare a to b, then b to c, then c to d, etc....  but if c were left blank for example, my attempt does not compare b to d.  But it is better than what I had.

 

<script type="text/javascript">
var Planning = 9686, PlanningDateValue;
var FieldworkStart = 9688, FieldworkStartDateValue;
var FiledworkComplete = 9689, FieldworkCompleteDateValue;
var WrapUp = 20591, WrapUpDateValue;
var Draft = 9690, DraftDateValue;
var Final = 9691, FinalDateValue;
var messageBoxText = "Invalid date entry. Please check your date values in the summary for validity. The following logic must apply:<br>Start of Planning < Start of Fieldwork < Fieldwork Completion < Wrap-Up Completion < Draft Report < Final Report";
var messageBoxTitle = 'Warning';
var daysToCompare = -1;
var oldApplyClick, oldSaveClick;
var start_array = [Planning, FieldworkStart, FiledworkComplete, WrapUp, Draft];
var end_array = [FieldworkStart, FiledworkComplete, WrapUp, Draft, Final];
var i

Sys.Application.add_load(function() {
$('#master_btnAdd').css('display', 'none');
$('#master_btnCopy').css('display', 'none');
$('#master_btnDelete').css('display', 'none');

// Hijack Save and Close Button
$('#master_btnSave').clone().attr('id', 'master_customBtnSave').insertBefore('#master_btnApply');
$('#master_btnSave').hide();
$('#master_customBtnSave').unbind('click').prop("onclick", null).click(function(){ DateCheck('save');return false;});

// Hijack Save Button
$('#master_btnApply').clone().attr('id', 'master_customBtnApply').insertBefore('#master_btnApply');
$('#master_btnApply').hide();
$('#master_customBtnApply').unbind('click').prop("onclick", null).click(function(){ DateCheck('apply');return false;});
});

function DateCheck(type) {
//Get Date Values

var datepass = 1;

for (i = 0; i < 5; i++) {

startDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(start_array[i], false)));
endDateValue = new Date(String(ArcherTech.UI.GenericContent.GetInstance().getFieldValue(end_array[i], false)));
if(startDateValue && endDateValue) {
if(daydiff(parseDate(startDateValue), parseDate(endDateValue)) <= daysToCompare) {
datepass = 0;
}
}
}
if(datepass == 1) {
SaveApply(type)
} else {
WarningAlert(messageBoxText,'',messageBoxTitle);
}

}

function SaveApply(action) {
if (action == 'save') {
$('#master_btnSave').click();
} else if (action == 'apply') {
$('#master_btnApply').click();
}
}

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

Hi,

I am trying to run it in 6.10 but I cannot even see the custom object on the layout.

Thanks,

Naomi