COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: Mpotla on 02 Jun 2009 07:23:32 AM

Title: Help in javascript in cognos 8.1
Post by: Mpotla on 02 Jun 2009 07:23:32 AM
Hi,
I have two value prompts:
[1] engine number
[2] package number
The user has to select only one, either engine number or package number. If he selects engine number then he should not be allowed to select package number and if he selects package number, he should not be allowed to select engine number.
Also he should be given flexibility to select either one.
need help urgent please dont mide for rushing up......
I have also attached the screen shot of the report requirement we got from customer.....


Any idea or solutions please pour in ....

thanks in advance,
Mohan Potla
Title: Re: Help in javascript in cognos 8.1
Post by: Desperado on 02 Jun 2009 11:41:58 AM
you can modify the below script and use this



<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;
   par1 = document.formWarpRequest._textEditBoxengn_Number.value;
   par2 = document.formWarpRequest._textEditBoxpkg_Number.value;
   if (par1 == "" && par2 =="")
   alert('Either engine number OR package number is Mandatory!');
   else promptButtonFinish();
}
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;
   }
}
</SCRIPT>
Title: Re: Help in javascript in cognos 8.1
Post by: Mpotla on 03 Jun 2009 01:21:55 AM
thanks a lot Desperado ,

I have named the two values prompts as 'ESN' for engine and 'PSN' for package.
I have edited the if statement so that if i alert the user in 2 cases:
[1] if both are selected
[2] if both and both are not selected

i have not written a javascript earlier so please dont mind and please explain me in detail what changes i have to do?
I have not understood what to pun in place of str and n in "function right(str, n)"........

attached is the sample changes i have done:

<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;
   par1 = document.formWarpRequest._oLstChoicesESN.options[0].selected;
   par2 = document.formWarpRequest._oLstChoicesPSN.options[0].selected;
   


if
(document.formWarpRequest._oLstChoicesESN.options[0].selected == true &&
document.formWarpRequest._oLstChoicesPSN.options[0].selected == true)
alert('Either engine number OR package number is Mandatory!');
else if (document.formWarpRequest._oLstChoicesESN.options[0].selected <> true &&
document.formWarpRequest._oLstChoicesPSN.options[0].selected <> true)
alert('Either engine number OR package number is to be selected; Not both!');
else promptButtonFinish();

}
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;
   }
}
</SCRIPT>




sorry for the trouble but please need help......

thanks in advacne,
Mohan POtla
Title: Re: Help in javascript in cognos 8.1
Post by: Desperado on 03 Jun 2009 08:25:02 AM
I think you cannot use olstchoices for the text box prompts. i remember that u r using text box prompts ...
use the same query , provide the name for the prompts in the properties as highlighted in red

<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;
   par1 = document.formWarpRequest._textEditBoxengn_Number.value;
   par2 = document.formWarpRequest._textEditBoxpkg_Number.value;
   if (par1 == "" && par2 =="")
   alert('Either engine number OR package number is Mandatory!');
   else promptButtonFinish();
}
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;
   }
}
</SCRIPT>