If you are unable to create a new account, please email support@bspsoftware.com

 

Problem with Autosubmit with default selection Date Prompts with javascripts

Started by chr.93, 06 Sep 2021 02:52:38 AM

Previous topic - Next topic

chr.93

I have a production report that runs with default date prompts based on the attached javascript that we use through a custom control.
The problem is that this report was running as expected and all of a sudden it stopped and the user must run the report once (the report gets the desirable prompt dates but outputs no data) and then select the Finish button to render the data. Previously this procedure was automatic.
To filter our data query we use the following macros:
[PNR_CREATION_DATE] between # prompt('pFromDate','date', '_first_of_month(_add_months(current_date,-1))')# and # prompt('pToDate','date', '_last_of_month(_add_months(current_date,-1))') #
Changing it into this: (?pFromDate? = 1900-01-01 AND [PNR_CREATION_DATE] BETWEEN _first_of_month(_add_months(current_date,-1)) AND _last_of_month(_add_months(current_date,-1)))
OR (?pFromDate? <> 1900-01-01 AND [PNR_CREATION_DATE] BETWEEN ?pFromDate? AND ?pToDate?)
we managed to achieve the automatic run of the report (without clicking on the Finish button), but the data were altered after every run, which means the dates taken, that filter the query every time are probably random.
Do you have any idea on how to resolve this sudden issue ?
Many thanks in advance!!

chr.93

Ι am facing an issue with uploading the attachment, so here is the used javascript.

define( [
     "/ibmcognos/samples/javascript/DatePromptPresetsNew/moment.js"
     ,"jquery"
     ,"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.bundle.min.js"
], function(  ) {
"use strict";


function FromToDateValidation()
{

};

FromToDateValidation.prototype.initialize = function( oControlHost, fnDoneInitializing )
{
     require( [
      "/ibmcognos/samples/javascript/DatePromptPresetsNew/jquery.lettering.js"
    , "/ibmcognos/samples/javascript/DatePromptPresetsNew/jquery.textillate.js"
    , "/ibmcognos/samples/javascript/DatePromptPresetsNew/jquery-ui.min.js"
   
    ]);
   
  var o = oControlHost.configuration
    , moment=require('/ibmcognos/samples/javascript/DatePromptPresetsNew/moment.js')
   
    , secondaryRun
    , dynStartDate
    , dynEndDate
    , datastores
    , textNoteElm
    , textNote = o["textNoteContainer"]
    ;
   
  this.ctrlFrom = o ? o["fromPrompt"] : 'fromDate';
  this.ctrlTo =   o ? o["toPrompt"] : 'toDate';
 
  secondaryRun = sessionStorage.getItem(this.ctrlFrom+'secondaryRun');

    //optional dynDate from configuration
    if(!secondaryRun&&o&&o["dynStartDate"]&&moment(eval(o["dynStartDate"])).isValid()) {
      dynStartDate=moment(eval(o["dynStartDate"])).format('DD-MM-YYYY');
    };

    //optional dynDate from configuration
    if(!secondaryRun&&o&&o["dynEndDate"]&&moment(eval(o["dynEndDate"])).isValid()) {
      dynEndDate=moment(eval(o["dynEndDate"])).format('DD-MM-YYYY');
    };
    //check for datasets
    if(oControlHost.control.dataStores) datastores = oControlHost.control.dataStores;

    if(datastores&&datastores.length>0){
      //if datastores have been found, let's start looking for minDate. First we loop through the datastores
      for(var i=0;i<datastores.length;++i){
        //then we loop through the columns
        for(var j=0;j<datastores.columnNames.length;++j){
          //test for dynDate
          if(datastores.columnNames[j]=='dynStartDate') dynStartDate = datastores.columnValues[j][0].substring(0,10);
          if(datastores.columnNames[j]=='dynEndDate') dynEndDate = datastores.columnValues[j][0].substring(0,10);
        }
      }
     
    };
   
      
var dateVal = oControlHost.page.getControlByName(this.ctrlFrom).getValues();
var dateValuse = dateVal[0].use;

//if(v.use = currentDay;

  if((!secondaryRun&&dynStartDate) || (secondaryRun&&dateValuse=='1900-01-01')) oControlHost.page.getControlByName(this.ctrlFrom).setValues([{'use':dynStartDate}]);
  if((!secondaryRun&&dynStartDate) || (secondaryRun&&dateValuse=='1900-01-01'))   oControlHost.page.getControlByName(this.ctrlTo).setValues([{'use':dynEndDate}]);
 
  sessionStorage.setItem(this.ctrlFrom+'secondaryRun',1);

//Create link to animate.css
if(!document.getElementById('animatecss')){
  var cssFile = document.createElement('link');
  cssFile.rel = 'stylesheet';
  cssFile.type = 'text/css';
  cssFile.id='animatecss';
  cssFile.href = '/ibmcognos/samples/javascript/DatePromptPresetsNew/animate.css';
  document.getElementsByTagName('head')[0].appendChild(cssFile)
}

if(!document.getElementById('bootstrapcss')){
  var cssFile = document.createElement('link');
  cssFile.rel = 'stylesheet';
  cssFile.type = 'text/css';
  cssFile.id='bootstrapcss';
  cssFile.href = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css';
  document.getElementsByTagName('head')[0].appendChild(cssFile)
 
}
 
var fromVal = function(values){
    var o = oControlHost.configuration
      , ctrlFrom = o ? o["fromPrompt"] : 'fromDate'
      , ctrlTo =   o ? o["toPrompt"] : 'toDate'
      , ctrl = oControlHost.page.getControlByName(ctrlFrom)
      , fromDt = moment(values[0].use).toDate()
     , fromDt_forMindate = values[0].use
      , toDt =   moment(oControlHost.page.getControlByName(ctrlTo).getValues()[0].use).toDate()
     , checkSameYearFlag = o.checkSameYearFlag ? o.checkSameYearFlag : 'No'
      , datastores =[]
      , minDate
      , textNoteElm
      , textNote = o["textNoteContainer"]
    ;


         if(textNote) {
        textNoteElm = oControlHost.page.getControlByName(textNote).element;
        $(textNoteElm).textillate({
          selector: '.texts',
          loop: false,
          minDisplayTime: 2000,
          initialDelay: 0,
          in: {
            effect: 'pulse',
            sync: true,
            reverse: false,
            shuffle: false,
            callback: function () {$(textNoteElm).textillate('out')}
          },
          out: {
            effect: 'fadeOut',
            delayScale: 1.5,
            delay: 2500,
            sync: true,
            reverse: false,
            shuffle: false,
            callback: function () {}
          },
          autoStart: false,
          inEffects: [],
          outEffects: [ 'hinge' ],
          callback: function () {},
          type: 'char'
        });
       
      }
     
   
    //basic check to ensure the from date is before than the to date.
    if(fromDt > toDt ) {
      ctrl.setValidator(function(){});
      ctrl.setValues(oControlHost.page.getControlByName(ctrlTo).getValues());
        if(textNote){
          $(textNoteElm).find('.texts li:first').text('Date From can not be later than Date To!');
         
          $(textNoteElm).textillate('start');
        }
      else {
        ctrl.element.setAttribute('data-content','Date From can not be later than Date To');
        ctrl.element.setAttribute('data-placement','top');
        ctrl.element.setAttribute('data-trigger','focus');
       
        $(ctrl.element).popover('show');
         
        setTimeout(function(){$(ctrl.element).popover('hide')},3000);
        ctrl.element.setAttribute('data-content','');
      }
      ctrl.setValidator(fromVal);   
      return true;
    }
//check to ensure the from date and end date are in the same year.
    else if (fromDt < toDt && fromDt.getFullYear() != toDt.getFullYear() && checkSameYearFlag == 'Yes') {
      
      ctrl.setValidator(function(){});
      //ctrl.setValues(oControlHost.page.getControlByName(ctrlTo).getValues());
        if(textNote){
          $(textNoteElm).find('.texts li:first').text('Οι ημερομηνίες από και έως πρέπει να είναι στο ίδιο έτος!');
         
          $(textNoteElm).textillate('start');
        }
      else {
        ctrl.element.setAttribute('data-content','Οι ημερομηνίες από και έως πρέπει να είναι στο ίδιο έτος!');
        ctrl.element.setAttribute('data-placement','top');
        ctrl.element.setAttribute('data-trigger','focus');
       
        $(ctrl.element).popover('show');
         
        setTimeout(function(){$(ctrl.element).popover('hide')},3000);
        ctrl.element.setAttribute('data-content','');
      }
      ctrl.setValidator(fromVal);   
      return true;
      
    }; 
   
         
    //optional minDate from configuration
    if(o&&o["minDate"]&&moment(eval(o["minDate"])).isValid()&&fromDt_forMindate < moment(eval(o["minDate"])).toDate()) {
      ctrl.setValidator(function(){});
      ctrl.setValues([{'use':moment(eval(o["minDate"])).format('DD-MM-YYYY')}]);
      if(textNote){
        $(textNoteElm).find('.texts li:first').text('Η Ημερομηνία από δεν μπορεί να οριστεί πριν την ' + moment(eval(o["minDate"])).format('DD-MM-YYYY'));
       
        $(textNoteElm).textillate('start');
      }
      else {
        ctrl.element.setAttribute('data-content','Η Ημερομηνία από δεν μπορεί να οριστεί πριν την ' + moment(eval(o["minDate"])).format('DD-MM-YYYY'));
        ctrl.element.setAttribute('data-placement','top');
        ctrl.element.setAttribute('data-trigger','focus');
       
        $(ctrl.element).popover('show');
        setTimeout(function(){$(ctrl.element).popover('hide')},3000);
        ctrl.element.setAttribute('data-content','');
      }
      ctrl.setValidator(fromVal);         
      return true;
    };

     

   //check for datasets
    if(oControlHost.control.dataStores) {
    datastores = oControlHost.control.dataStores;


      if(datastores&&datastores.length>0){
        //if datastores have been found, let's start looking for minDate. First we loop through the datastores
        for(var i=0;i<datastores.length;++i){
          //then we loop through the columns
          for(var j=0;j<datastores.columnNames.length;++j){
            //test each column for minDate, and if we find it populate minDate
            if(datastores.columnNames[j]=='minDate') {
              minDate = datastores.columnValues[j][0].substring(0,10);
              if(fromDt_forMindate < moment(minDate).toDate()) {
                ctrl.setValidator(function(){});
                ctrl.setValues([{'use':minDate}]);
                if(textNote){
                  $(textNoteElm).find('.texts li:first').text('Η Ημερομηνία από δεν μπορεί να οριστεί πριν την ' + moment(minDate).format('DD-MM-YYYY'));
                 
                  $(textNoteElm).textillate('start');
                }
                else {
                  ctrl.element.setAttribute('data-content','Η Ημερομηνία από δεν μπορεί να οριστεί πριν την ' + moment(minDate).format('DD-MM-YYYY'));
                  ctrl.element.setAttribute('data-placement','top');
                  ctrl.element.setAttribute('data-trigger','focus');
                 
                  $(ctrl.element).popover('show');
                  setTimeout(function(){$(ctrl.element).popover('hide')},3000);
                  ctrl.element.setAttribute('data-content','');
                }

                ctrl.setValidator(fromVal);         
              }
            }
          }
        }
      }
    };
           
    return true;
  }
 
  oControlHost.page.getControlByName(this.ctrlFrom).setValidator(fromVal);
     
     

var toVal = function(values){
  var o = oControlHost.configuration
    , ctrlFrom = o ? o["fromPrompt"] : 'fromDate'
    , ctrlTo =   o ? o["toPrompt"] : 'toDate'
    , ctrl = oControlHost.page.getControlByName(ctrlTo)
    , fromDt = moment(oControlHost.page.getControlByName(ctrlFrom).getValues()[0].use).toDate()
    , toDt =   moment(values[0].use).toDate()
   , toDt_forMaxDate = values[0].use
    , checkSameYearFlag = o.checkSameYearFlag ? o.checkSameYearFlag : 'No'   
    , datastores =[]
    , maxDate
    , textNoteElm
    , textNote = o["textNoteContainer"]
;


     
      if(textNote) {
        textNoteElm = oControlHost.page.getControlByName(textNote).element;
        $(textNoteElm).textillate({
          selector: '.texts',
          loop: false,
          minDisplayTime: 2000,
          initialDelay: 0,
          in: {
            effect: 'pulse',
            sync: true,
            reverse: false,
            shuffle: false,
            callback: function () {$(textNoteElm).textillate('out')}
          },
          out: {
            effect: 'fadeOut',
            delayScale: 1.5,
            delay: 2500,
            sync: true,
            reverse: false,
            shuffle: false,
            callback: function () {}
          },
          autoStart: false,
          inEffects: [],
          outEffects: [ 'hinge' ],
          callback: function () {},
          type: 'char'
        });
       
      }
     

    //basic check to ensure the from date is before than the to date.
    if(fromDt > toDt ) {
     
      var dt = oControlHost.page.getControlByName(ctrlFrom).getValues()[0].use;
      ctrl.setValidator(function(){});
      ctrl.setValues([{'use':dt}]);
      if(textNote){
        $(textNoteElm).find('.texts li:first').text('Date To can not be earlier than Date From!');
       
        $(textNoteElm).textillate('start');
      }
      else {
        ctrl.element.setAttribute('data-content','Date To can not be earlier than Date From!');
        ctrl.element.setAttribute('data-placement','top');
        ctrl.element.setAttribute('data-trigger','focus');
       
        $(ctrl.element).popover('show');
        setTimeout(function(){$(ctrl.element).popover('hide')},3000);
        ctrl.element.setAttribute('data-content','');
      }
      ctrl.setValidator(toVal);
        return true;
      }
//check to ensure the from date and end date are in the same year.
    else if (fromDt < toDt && fromDt.getFullYear() != toDt.getFullYear() && checkSameYearFlag == 'Yes') {
      
      ctrl.setValidator(function(){});
     ctrl.setValues(oControlHost.page.getControlByName(ctrlFrom).getValues());
        if(textNote){
          $(textNoteElm).find('.texts li:first').text('Οι ημερομηνίες από και έως πρέπει να είναι στο ίδιο έτος!');
         
          $(textNoteElm).textillate('start');
        }
      else {
        ctrl.element.setAttribute('data-content','Οι ημερομηνίες από και έως πρέπει να είναι στο ίδιο έτος!');
        ctrl.element.setAttribute('data-placement','top');
        ctrl.element.setAttribute('data-trigger','focus');
       
        $(ctrl.element).popover('show');
         
        setTimeout(function(){$(ctrl.element).popover('hide')},3000);
        ctrl.element.setAttribute('data-content','');
      }
      ctrl.setValidator(toVal);   
      return true;
      
    };      
     
       
    //optional maxDate from configuration
    if(o&&o["maxDate"]&&moment(eval(o["maxDate"])).isValid()&&toDt_forMaxDate >  moment(eval(o["maxDate"])).format("DD-MM-YYYY")) {
      var dt = moment(eval(o["maxDate"])).format('DD-MM-YYYY');
      ctrl.setValidator(function(){});
      ctrl.setValues([{'use':dt}]);
      if(textNote){
        $(textNoteElm).find('.texts li:first').text('Η Ημερομηνία έως δεν μπορεί να οριστεί μετά την ' + moment(eval(o["maxDate"])).format('DD-MM-YYYY'));
       
        $(textNoteElm).textillate('start');
      }
      else {
        ctrl.element.setAttribute('data-content','Η Ημερομηνία έως δεν μπορεί να οριστεί μετά την ' + moment(eval(o["maxDate"])).format('DD-MM-YYYY'));
        ctrl.element.setAttribute('data-placement','top');
        ctrl.element.setAttribute('data-trigger','focus');
       
        $(ctrl.element).popover('show');
        setTimeout(function(){$(ctrl.element).popover('hide')},3000);
        ctrl.element.setAttribute('data-content','');
      }
       ctrl.setValidator(toVal);
      return true;
      };
   
    //check for datasets.
    if(oControlHost.control.dataStores) {
    datastores = oControlHost.control.dataStores;

      if(datastores&&datastores.length>0){
        //if datastores have been found, let's start looking for minDate. First we loop through the datastores
        for(var i=0;i<datastores.length;++i){
          //then we loop through the columns
          for(var j=0;j<datastores.columnNames.length;++j){
            //test each column for maxDate, and if we find it, test if the date exceeds
            if(datastores.columnNames[j]=='maxDate') {
              maxDate = datastores.columnValues[j][0].substring(0,10);
              if(toDt_forMaxDate > maxDate) {
                ctrl.setValidator(function(){});
                ctrl.setValues([{'use':maxDate}]);
                if(textNote){
                  $(textNoteElm).find('.texts li:first').text('Η Ημερομηνία έως δεν μπορεί να οριστεί μετά την ' + moment(maxDate).format('DD-MM-YYYY'));
                 
                  $(textNoteElm).textillate('start');
                }
                else {
                  ctrl.element.setAttribute('data-content','Η Ημερομηνία έως δεν μπορεί να οριστεί μετά την ' + moment(maxDate).format('DD-MM-YYYY'));
                  ctrl.element.setAttribute('data-placement','top');
                  ctrl.element.setAttribute('data-trigger','focus');
                 
                  $(ctrl.element).popover('show');
                  setTimeout(function(){$(ctrl.element).popover('hide')},3000);
                }


                ctrl.setValidator(toVal);
              }
            }
          }
        }
      }
    };
    return true;
  };
 
  oControlHost.page.getControlByName(this.ctrlTo).setValidator(toVal);
   


fnDoneInitializing();
   
};

FromToDateValidation.prototype.draw = function( oControlHost)
{
   
};
return FromToDateValidation;
});   

dougp

OK.  Not troubleshooting that volume of JavaScript...

There is a lot missing from your problem statement, and I never assume that the obvious is obvious, so let's clarify:

Your filters are dramatically different.

Quotethe data were altered
This may have been because the two queries are different, and so are being handled differently by the RDBMS's optimization engine.  You may have the same results in a different order.  Verify that you have a meaningful ORDER BY intended to ensure the same results every time.


Quotewithout clicking on the Finish button
I'm not sure what you mean here.  Are you saying that the user should never see the prompt page?
This doesn't seem like something that would be affected by a custom control employing JavaScript to set default values for date prompts.  You should look at the feature in your report that was designed specifically to auto-submit the report.


Quotethis report was running as expected and all of a sudden it stopped
Assuming you mean the auto-submit functionality stopped...  What changed in the environment?  Was there a recent upgrade?  Did you recently begin using SSL or SSO?  Was part of the underlying system modified?