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

You'd just need to convert the text to an array and reference name.

 

Which can be done like so:

var valuesListValue = JSON.parse($('input[id*="f29963c_shf"').val());
alert(valuesListValue.text);‍‍

 Advisory Consultant

thanks a lot David, default JSON parser worked thanks a lot for the suggestion.

Hi David! I am trying to do something similar but get "showPop is undefined" from the else statement with the following code. The field I'm looking for is on layout but it is a calculated field. Is that the problem? What should I do differently?

 

<script>
Sys.Application.add_load(function() {
     var winMsg = '<p>This application has previously reported vulnerabilities.</p>';

     var winTitle = 'Warning - Open Vulnerabilities';

     var showPop = $('input[id*="s3078_f22411c"').val();

 

     function shouldShow() {

          if (showPop == "Yes") { 

               // Hijack the Save Button

               $('#master_btnSave').attr('href',"#").removeAttr('onclick').unbind('click').prop("onclick", null);    
               $('#master_btnSave').click(function(event){ 
                    var userConfirmed = function(arg){
                         if(arg) {
                               __doPostBack('master$btnSave','');
                              console.log("showPop is " + showPop);
                         }
                    };
                    WarningConfirm(winMsg, userConfirmed,winTitle);
               });
          } else {
               console.log ("showPop is " + showPop);

          }

     };
     shouldShow(); 

});
</script>

Lee when you define variables inside a function they are local (non-global) and can't be referenced outside said function.

 

See how the below changes work.

<script type="text/javascript">
     var winMsg = '<p>This application has previously reported vulnerabilities.</p>';
     var winTitle = 'Warning - Open Vulnerabilities';
     var showPop;

     Sys.Application.add_load(function() {
          showPop = $('input[id*="s3078_f22411c"').val();
          shouldShow();
     });

     function shouldShow() {
          if (showPop == "Yes") {
               // Hijack the Save Button
               $('#master_btnSave').attr('href',"#").removeAttr('onclick').unbind('click').prop("onclick", null);
               $('#master_btnSave').click(function(event){
                    var userConfirmed = function(arg){
                         if(arg) {
                              __doPostBack('master$btnSave','');
                              console.log("showPop is " + showPop);
                         }
                    };
                    WarningConfirm(winMsg, userConfirmed,winTitle);
               });
          } else {
               console.log ("showPop is " + showPop);
          }
     }
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 

If you using 6.3+, it best to hijack the Save and Save and Close buttons this way:

// 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(){ CheckUsers('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(){ CheckUsers('apply');return false;});

Then call the original buttons to save; Save = $('#master_btnApply').click(); Save and Close  = $('#master_btnSave').click();

 Advisory Consultant

Whoa, an embarrassing rookie mistake! Sorry! I made the changes you suggested but I’m still getting undefined for that field. I am able to get information for other fields (if I just change the field ID in the showPop assignment statement) which is why I thought it was the calculation making it weird. What else I can try?

No worries

 

Replace line 7 with, showPop = $('input[id*="f22411c"').val();  also if it's a calculated values list try, showPop = $('input[id*="f22411c"').val().trim();

 

Is the field referenced by the showPop variable on the layout?

 Advisory Consultant

Yes, the field referenced by showPop is on the layout. I replaced what you indicated and still got undefined. I made the field a manual selection instead of calculated it works that way! How does Archer reference it differently if it’s calculated?

 

Lee

My bad, plus early it was morning , when it comes to calculated fields there is no input element for them.  The value is typically in a span element, $('span[id*="f22411c"]').text().trim();  Also noticed just now a closing ] was missing from that line.

 Advisory Consultant

I finally worked it out by digging through the DOM – I had to use this:

 

$('input[name*="$s3078$ctl11"]').val();

 

To get the value I need. You gave me the right hint with your last message (input vs. span). Thanks for your help!

Hi David, Can you please help with below code, it is not working in 6.5

 

<script type="text/javascript">
var startDate = 12345, startDateValue;
var endDate = 54678, endDateValue;
var messageBoxText = "Please select a valid end date. End date cannot be before Start date";
var messageBoxTitle = 'Warning';
var daysToCompare = -1;
var master_btnSave, master_btnApply

Sys.Application.add_load(function() {
// Hijack Save/Apply Buttons
// 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(){ CheckUsers('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(){ CheckUsers('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 $('#master_btnSave').click();
} else if (action == 'apply') {
return $('#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>