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

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Java Script correction Required

Started by Desperado, 29 May 2007 03:03:46 PM

Previous topic - Next topic

Desperado

Hi,

I need some correction in a javascript for date validation. The error I'm getting is, when ever i run the report , for any selected value , it's popping out the alert.



here is the script:

<script>
var cntlName;
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function customCheckPage(){
var par1;
var par2;
for( var i=0; i<preProcessControlArray.length; i++){
  cntlName = eval(preProcessControlArray);
  if ( cntlName.m_oSubmit.name.toLowerCase() == 'Par_FromDate' ){
    eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
    par1 = cntlName.m_oForm.value;
  }   
  if ( cntlName.m_oSubmit.name.toLowerCase() == 'Par_ToDate' ){
    eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
    par2 = cntlName.m_oForm.value;
  }
}
  if (par1<=par2)
    promptButtonFinish();
  else
    alert('FROM DATE parameter must be smaller than or equal to TO DATE parameter!');
}
for( var i=0; i<pageNavigationObserverArray.length; i++){
  cntlName = eval( pageNavigationObserverArray );
  if(cntlName.m_oParent.onclick.toString().indexOf('promptButtonFinish()')>0 ){
    cntlName.m_oParent.onclick = customCheckPage;
  }
}
for( var i=0; i<preProcessControlArray.length; i++){
  cntlName = eval(preProcessControlArray);
  dt = new Date();
  df = new Date( dt - 30*86400000);
  if (cntlName.m_oSubmit.name.toLowerCase() == 'Par_FromDate' ){
    cntlName.m_oEditBox.value = df.getFullYear()
         + '-' + right('0'+(1+df.getMonth()),2)
         + '-' + right('0'+df.getDate(),2);
    eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
  }
  if (cntlName.m_oSubmit.name.toLowerCase() == 'Par_ToDate' ){
    cntlName.m_oEditBox.value = dt.getFullYear()
         + '-' + right('0'+(1+dt.getMonth()),2)
         + '-' + right('0'+dt.getDate(),2);
    eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
  }
}
</script>


Thanks in Advance

COGNOiSe administrator

First of all ....... STOP CALLING IT YOUR SCRIPT ! ...  >:(   I've wrote it about a year ago for Hewitt in Lincolnshire, IL ...

Second, which alert box are you getting?

Desperado

That might be ur script. I also worked for Hewitt in charlotte , and i got it from there. I think it's not copyrighted  ;) ....okay...
The problem now is I'm testing it in cognos 8.2 with two date prompts "from date" and "to date ". so, when the from date is may 1 2007 and to date is may 31 2007  it shouldn't show any alert for me . But it's showing me an alert like " From date should be smaller than the to date" ...

Your script is awesome. Can you suggest me some good site where i can learn javascripting ? :)

Thanks in Advance


Desperado

Is that okay now Cognoise Administrator  ?
Good work Dude :)

COGNOiSe administrator

A good website for anything HTML related is w3schools.

as for your, pardon mine, script, the problem is:

cntlName.m_oSubmit.name.toLowerCase() == 'Par_FromDate'

it should be

cntlName.m_oSubmit.name.toLowerCase() == 'par_fromdate'

Every time you you toLowerCase() the string you compare it to should be using only lower case characters.

Desperado

Hi,

I tried using lowercase. But the problem is still there .....


if (par1<=par2)
//alert ('CORRECT');   
promptButtonFinish();
  else
alert('FROM DATE parameter must be smaller than or equal to TO DATE parameter!');

i think the problem is at this part of the code . When i use the first alert, it's going into the report irrespective of date. I mean second alert is not working (even if par1>par2).
if i comment the first alert, then it's popping the alert even when (par1<par2)...


Thanks in Advance....

COGNOiSe administrator

This is a different problem.

It should be:

if (par1<=par2) {
  //alert ('CORRECT');   
  promptButtonFinish();
} else {
  alert('FROM DATE parameter must be smaller than or equal to TO DATE parameter!');
}

Desperado

This is also not working .... I tried changing my script with that ..... It's not showing the alert at all .
this is the latest script .....

<script>
var cntlName;
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function customCheckPage(){
var par1;
var par2;
for( var i=0; i<preProcessControlArray.length; i++){
  cntlName = eval(preProcessControlArray);
  if ( cntlName.m_oSubmit.name.toLowerCase() == 'par_fromdate' ){
    eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
    par1 = cntlName.m_oForm.value;
  }   
  if ( cntlName.m_oSubmit.name.toLowerCase() == 'par_todate' ){
    eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
    par2 = cntlName.m_oForm.value;
  }
}

if (par1<=par2) {
  //alert ('CORRECT');   
  promptButtonFinish();
} else {
  alert('FROM DATE parameter must be smaller than or equal to TO DATE parameter!');
}

for( var i=0; i<pageNavigationObserverArray.length; i++){
  cntlName = eval( pageNavigationObserverArray );
  if(cntlName.m_oParent.onclick.toString().indexOf('promptButtonFinish()')>0 ){
    cntlName.m_oParent.onclick = customCheckPage;
  }
}
for( var i=0; i<preProcessControlArray.length; i++){
  cntlName = eval(preProcessControlArray);
  dt = new Date();
  df = new Date( dt - 30*86400000);
  if (cntlName.m_oSubmit.name.toLowerCase() == 'par_fromdate' ){
    cntlName.m_oEditBox.value = df.getFullYear()
         + '-' + right('0'+(1+df.getMonth()),2)
         + '-' + right('0'+df.getDate(),2);
    eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
  }
  if (cntlName.m_oSubmit.name.toLowerCase() == 'par_todate' ){
    cntlName.m_oEditBox.value = dt.getFullYear()
         + '-' + right('0'+(1+dt.getMonth()),2)
         + '-' + right('0'+dt.getDate(),2);
    eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
  }
}
</script>

Thanks in Advance

Desperado

The version of Cognos I'm using is 8.2. will that be a problem ????

COGNOiSe administrator


Desperado


COGNOiSe administrator

You should be comparing parameter names to 'p_' concateneted with parameter name, so every reverence of par_fromdate should be p_par_fromdate (same for to date).

Desperado

Thanks Dude .... It's working now  :)