Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 


#Product
#Analytics
#CognosAnalytics
#Analyticstools
#TechXchange Partner
#TechXchange Session
#TechXchange Presenter
#AI
 View Only
Expand all | Collapse all

Set dynamically (e.g. using javascript) default selections in a multi-select prompt

  • 1.  Set dynamically (e.g. using javascript) default selections in a multi-select prompt

    Posted 11/03/21 12:48 PM
    Hi,

    I'd like to ask if there is anyone that has solved the specific issue, set dynamically default selections in a multi-select prompt, either with javascript or by using any other workaround.

    Thanks in advance,

    Pantelis Stavroulidakis

    ------------------------------
    Pantelis Stavroulidakis
    ------------------------------

    #CognosAnalyticswithWatson


  • 2.  RE: Set dynamically (e.g. using javascript) default selections in a multi-select prompt
    Best Answer

    Posted 11/03/21 03:46 PM

    Hi,

    It's is pretty easy using Custom Controls.

    Take a look at https://community.ibm.com/community/user/businessanalytics/blogs/steven-macko/2018/09/10/javascript-samples-for-ibm-cognos-analytics

    I wrote this code and add a custom control in report that references js file.

    This control catches item values added to custom control data store and make then selected in the prompt.

    define(function() {
        "use strict";
    
        function SetValuePrompt() {};
    
        SetValuePrompt.prototype.draw = function(oControlHost) {
    
            var o = oControlHost.configuration;
            var oDataStore = oControlHost.control.dataStores[0];
            var iRowCount = oDataStore.rowCount;
            var sValue = [];
    
            for (var i = 0; i < iRowCount; i++) {
                sValue.push({
                    "use": oDataStore.getCellValue(i, 0)
                });
            }
    
            oControlHost.page.getControlByName(o["promptName"]).setValues(sValue);
            oControlHost.valueChanged();
            if(!o["submit"]) oControlHost.next();
        };
    
        return SetValuePrompt;
    
    });


    ------------------------------
    JEAM COELHO
    Cognos Solution Architect

    LinkedIn: https://www.linkedin.com/in/jeamcoelho/
    ------------------------------



  • 3.  RE: Set dynamically (e.g. using javascript) default selections in a multi-select prompt

    Posted 11/05/21 03:23 AM
    Dear Jeam,

    Thanks for your suggestion.
    I used the script that you send me and I tried it but i got an error (see debug2.JPG) that the object does not support property or method  "set values". I changed it also as you can see below to get the promptName, using configuration but I still got the same error. I performed debugging and I found that prompt object was not recognized (see debug2.JPG).
    I'm also attaching the sample report (Report.txt) that I used to perform the test which is based on Great outdoors data module.

    I will appreciate any suggestion for the cause of this error. 
    define(
           function() 
    	{ 
    	   "use strict"; 
    	   
    	   
    	      function SetValuePrompt() {
    			  
    		  };
    		  
    		  
    		  SetValuePrompt.prototype.draw = function(oControlHost) 
    		  {
    			  var o = oControlHost.configuration; 
    			  this.ctrlFrom = o["promptName"]; 
    			  var oDataStore = oControlHost.control.dataStores[0]; 
    			  var iRowCount = oDataStore.rowCount; 
    			  var sValue = []; 
    			 for (var i = 0; i < iRowCount; i++) {
    													sValue.push({ "use": oDataStore.getCellValue(i, 0) }); 
    											     } 
    		     this.ctrlFrom.setValues(sValue);
    			 oControlHost.valueChanged(); 
    			 if(!o["submit"]) oControlHost.next(); 
    		   }; 
    			 return SetValuePrompt; 
    	}
    );​

    Kind Regards,

    Pantelis Stavroulidakis

    ------------------------------
    Pantelis Stavroulidakis
    ------------------------------



  • 4.  RE: Set dynamically (e.g. using javascript) default selections in a multi-select prompt

    Posted 11/05/21 06:09 AM
    You're missing the getControl function, so this.ctrlFrom is just a string. Change that to:

    this.ctrlFrom = oControlHost.page.getControlByName(o["promptName"])​​


    ------------------------------
    Paul Mendelson
    ------------------------------



  • 5.  RE: Set dynamically (e.g. using javascript) default selections in a multi-select prompt

    Posted 11/05/21 07:26 AM

    Dear Paul,

     

    I followed your suggestion as you may see in the code below but another error pop up (see the image below).

     

     

     

    Below you may see that the object is read correct and the values are set.

     

    define(

           function()

                   {

                      "use strict";

                      

                      

                         function SetValuePrompt() {

                                                  

                                    };

                                   

                                    

                                    SetValuePrompt.prototype.draw = function(oControlHost)

                                    {

                                                   var o = oControlHost.configuration;

                                                   this.ctrlFrom =oControlHost.page.getControlByName(o["promptName"]);

                                                   var oDataStore = oControlHost.control.dataStores[0];

                                                   var iRowCount = oDataStore.rowCount;

                                                   var sValue = [];

                                                  for (var i = 0; i < iRowCount; i++) {

                                                                                                                                                                                                       sValue.push({ "use": oDataStore.getCellValue(i, 0) });

                                                                                                                                                                              }

                                       this.ctrlFrom.setValues(sValue);

                                                 oControlHost.valueChanged();

                                                  if(!o["submit"]) oControlHost.next();

                                     };

                                                  return SetValuePrompt;

                   }

    );

     

    I'll appreciate any suggestion that you may have.

     

    Kind Regards,

    Pantelis Stavroulidakis

    Senior Consultant

     

     

    Grammou 71, GR 15124 Athens

     

    Phone:   +30 210 8056826

    FAX:        +30 210 8056828

    Mobile: +30 697 2364555

    E-mail:    p.stavroulidakis@ergoman.net

    Webex:   https://ergoman.webex.com/meet/p.stavroulidakis

    WEB :     www.ergoman.net

     

    PLEASE VISIT OUR NEW WEB SITE : www.ergoman.net

     

    This message is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone. Internet communications are not secure and therefore Ergoman does not accept legal responsibility for the contents of this message and for any damage whatsoever that is caused by viruses being passed.

    P Please consider the environment before printing this e-mail

     

     






  • 6.  RE: Set dynamically (e.g. using javascript) default selections in a multi-select prompt

    Posted 11/05/21 07:56 AM
    It looks like you get that error if the value you're trying to set doesn't exist in the value prompt. Can you make sure one of the options in the prompt has a use value of 2017?

    You could also try using a text prompt instead of a value prompt.

    ------------------------------
    Paul Mendelson
    ------------------------------



  • 7.  RE: Set dynamically (e.g. using javascript) default selections in a multi-select prompt

    Posted 11/05/21 09:30 AM

    Sorry for being annoying but I have another problem now, since I corrected the one based on your answer: The page seems to loop infinitely, although I tried to set reprompt() and finish() instead of next.

     

    define(

           function()

                   {

                      "use strict";

                      

                      

                         function SetValuePrompt() {

                                                  

                                    };

                                   

                                    

                                    SetValuePrompt.prototype.draw = function(oControlHost)

                                    {

                                                   var o = oControlHost.configuration;

                                                   this.ctrlFrom =oControlHost.page.getControlByName(o["promptName"]);

                                                   var oDataStore = oControlHost.control.dataStores[0];

                                                   var iRowCount = oDataStore.rowCount;

                                                   var sValue = [];

                                                  for (var i = 0; i < iRowCount; i++) {

                                                                                                                                                                                                       sValue.push({ "use": oDataStore.getCellValue(i, 0) });

                                                                                                                                                                              }

                                       this.ctrlFrom.setValues(sValue);

                                                 oControlHost.valueChanged();

                               if(!o["submit"]) oControlHost.reprompt();

                                                

                                     };

                                                  return SetValuePrompt;

                   }

    );

     

    Kind Regards,

    Pantelis Stavroulidakis

    Senior Consultant

     

     

    Grammou 71, GR 15124 Athens

     

    Phone:   +30 210 8056826

    FAX:        +30 210 8056828

    Mobile: +30 697 2364555

    E-mail:    p.stavroulidakis@ergoman.net

    Webex:   https://ergoman.webex.com/meet/p.stavroulidakis

    WEB :     www.ergoman.net

     

    PLEASE VISIT OUR NEW WEB SITE : www.ergoman.net

     

    This message is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. If you have received it by mistake, please let us know by e-mail reply and delete it from your system; you may not copy this message or disclose its contents to anyone. Internet communications are not secure and therefore Ergoman does not accept legal responsibility for the contents of this message and for any damage whatsoever that is caused by viruses being passed.

    P Please consider the environment before printing this e-mail

     

     






  • 8.  RE: Set dynamically (e.g. using javascript) default selections in a multi-select prompt

    Posted 11/05/21 11:36 AM
    Finally I've managed to eliminate the infinite loop when I comment out
    the line if(!o["submit"]) oControlHost.reprompt();

    I'd like to thank you both, Paul and Jeam, for your valuable help.

    Kind Regards


    ------------------------------
    Pantelis Stavroulidakis
    ------------------------------



  • 9.  RE: Set dynamically (e.g. using javascript) default selections in a multi-select prompt

    Posted 11/05/21 03:27 AM
      |   view attached
    The upload also the report definition because I forgot it.

    ------------------------------
    Pantelis Stavroulidakis
    ------------------------------

    Attachment(s)

    txt
    Report.txt   6 KB 1 version