COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: NewGuy1983 on 30 Nov 2018 04:23:32 PM

Title: Javascript within Page module
Post by: NewGuy1983 on 30 Nov 2018 04:23:32 PM
Hello,

I'm trying implement some validation on some value prompts and I have deployed my .JS file on the cognos server. I've reviewed IBM's documentation and I see that Page Module's and Custom controls use AMD modules. I'm fairly new to this topic.

Running Cognos 11.0.12

I followed the samples provided by IBM and have set a validator on one of my controls like the IBM's example.

PageModule.prototype.load = function( oPage )
{
   oPage.getControlByName( "txtPhoneNumber" ).setValidator( fnTelephoneValidator );
};

When I call my "fnTelephoneValidator " function I need to check the value of another value prompt within this method. How do we get controls outside of these other modules? Do I have to set a global variable "oPage"? If so can someone show me an example? I'm struggling with syntax. Thank you
Title: Re: Javascript within Page module
Post by: NewGuy1983 on 03 Dec 2018 02:02:34 PM
I was able to get my other controls. Now I'm unable to force a page reprompt. Can someone help with me the syntax? This no longer works within a page module

oCR.sendRequest (cognos.Report.Action.REPROMPT);
Title: Re: Javascript within Page module
Post by: CognosPaul on 03 Dec 2018 08:41:49 PM
Super simple now:

oControlHost.reprompt()
or
oControlHost.finish()
Title: Re: Javascript within Page module
Post by: NewGuy1983 on 04 Dec 2018 08:04:23 AM
Thanks for your response Paul. I'm receiving 'oContorlHost is not defined'. I believe I need to define within another module, is that correct? Below is a sample file. I've written standard JS but am new to this so if this is all wrong please let me know. Thanks

define( function() {
"use strict";

function PageModule()
{
};

PageModule.prototype.load = function( oPage )
{   
   oPage.getControlByName( "testId" ).setValidator( fntestId );
   
   
function fntestId( aValues )
{
   //do work
   
   if (repromptIsNeeded){
      oControlHost.reprompt();
      return false;
   }else{
      return true;
   }
}
};

return PageModule;
});
Title: Re: Javascript within Page module
Post by: CognosPaul on 04 Dec 2018 09:04:40 AM
It's my own fault for not having read closely enough. It looks like Page Modules don't support submitting the page. You'll have to use a custom control.

define( [], function(  ) {
"use strict";


function validate()
{
};

validate.prototype.initialize = function( oControlHost, fnDoneInitializing )
{

var fntestId = function( aValues )
{
   //do work
   
   if (repromptIsNeeded){
      oControlHost.reprompt();
      return false;
   }else{
      return true;
   }
oControlHost.page.getControlByName('testId; ).setValidator( fntestId );


fnDoneInitializing();

};


   
}
};
return validate;
});


Make sure to set the control to "No UI".