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

 

How to set the default value for value prompt in cognos Analytics reporting

Started by lalitha.nov20, 26 May 2017 05:51:06 AM

Previous topic - Next topic

lalitha.nov20

Hi All,

We have migrated most of report from cognos 10.2.2 to cognos 11 now. We are using java scripts to select the first value of the value prompt. How can this be written for cognos 11. I have ssas cube as a source.

We have script that work on relational data. Calling this below script using custom control works.

here is my understand why this is not working for cube source. In my report, use value is different from display value and this scripts reads the display value from the list and trying to set the display value to use value.can any one help me how can we read the use value.

Script

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

function PromptDefaultSelection()
{
};
PromptDefaultSelection.prototype.draw = function( oControlHost ) {
    //variable to reference the json config
    var conf = oControlHost.configuration;
    if(!conf){
        throw new scriptableReportError("PromptDefaultSelection", "draw method", "Missing configuration.");
    }
    //if(!(conf.hasOwnProperty("height") && conf.hasOwnProperty("width") && conf.hasOwnProperty("controlName"))){
      //  throw new scriptableReportError("PromptDefaultSelection", "draw method",
      //  "Configuration object needs at least two properties (height;width;controlName)");
   // }
        var oControl = oControlHost.page.getControlByName(conf.controlName);
   var promptControlID = oControlHost.page.getControlByName(conf.controlName).element.id;
   //var sValue = "[Operations].[Client].[Client.Client].[Client]->:[M14].[[Client]].[Client]].&[1000001]]]";
        //alert(sValue);
   var promptDivId = $("#" + promptControlID).find("table")[0].id;
   var dropDownDivId = promptDivId+"_ListViewDropDown";
   var sValue =$($("#"+dropDownDivId).find('tr')[2]).find('span')[0].innerHTML;   
        alert(sValue);
   oControl.addValues ( [JSON.parse('{"use":"'+sValue+'"}')] );
   var control = $("#" + promptControlID);
   control.css("min-width", conf.width);
   control.css("width", conf.width);
//Config is good so we move on.

};
return PromptDefaultSelection;
});

Thank you,
Lalitha


dougp

First, don't expect others to troubleshoot the main body of your code for you.  That's your job.  If you have a specific location in the code that needs attention, I'll find it by reading your comments...

If I remove all lines from your code that are not comments I get:

Quote
//variable to reference the json config
//Config is good so we move on.

So -- you get the config, and the config is good, and you're done.  According to your comments, the script doesn't do anything after validating the configuration object.

lalitha.nov20

Hi dougp,

I didnt expect to troubleshoot the code. I just looking for way how can extract the use value of the prompt which i am missing in the code. My code only extracts the display value and was check if any one has worked on these kind of scripts for cognos 11.


Here is the code that i missing.. how to extract the use value ..

var dropDownDivId = promptDivId+"_ListViewDropDown";
   var sValue =$($("#"+dropDownDivId).find('tr')[2]).find('span')[0].innerHTML;   
        alert(sValue);
   oControl.addValues ( [JSON.parse('{"use":"'+sValue+'"}')] );

CognosPaul

Cognos has an API that's dedicated for exactly this type of request, and what confuses me is that API is being used to some extent.

So it looks like the code is finding the table in the prompt, and focusing down on the span inside the prompt. From what I can gather, it looks like you're trying to select the first value of the prompt? You can replace almost all of it with:


var oControl = oControlHost.page.getControlByName(conf.controlName);
oControl.setValues([oControl.getValues(true)[2]]);


Also, why are you going through the element to get the ID, then using the ID to find the element?



var control=$(oControl.element);
control.css=stuff

dougp

I was confused as well.  It looks like there's some hinky stuff going on in that code.  I figured there must be a reason that could be adding more comments to the code.

//I'm trying to do B because A doesn't work...

CognosPaul

Thinking about this some more, Lalitha, you should read my article found here: http://www.pmsquare.com/main/blog/cognos-analytics-custom-javascript-date-prompts-datasets/

Since you can assign a query directly to a JavaScript control, you could directly set the prompt however you want. The example on the blog is for date prompts, but the logic will work just as well with value prompts.

I'm currently working on a script that will give you a finer grain of control over the style of the prompt and it should be published later this month.

lalitha.nov20

Hi Paul,

Thank you for the reply.

I tried the code provided within an prototype.initialize method.

var conf = oControlHost.configuration
var oControl = oControlHost.page.getControlByName(conf.controlName);
       oControl.setValues([oControl.getValues(true)[2]]);

It throws an error " Cannot read property 'use' of undefined. Is there something i am still missing?


Thank you.,
Lalitha

lalitha.nov20

Hi Paul,

I also debugged the code as to why is that we are not getting the value of the array. It seems that getControlByName(conf.controlName) is not providing all the array that is defined for the value prompt that is suppose to as in cognos 10.2. I see only one array and that is the default parameter name that gets displayed in the value prompt when the report is executed.

Is there any way that we can get a work around on this?

Your suggestion is much appreciated!

Thank you,
Lalitha


CognosPaul

Try oControl.setValues([oControl.getValues(true)[0]]);

The previous one was attempting to get the third value, but if there's only one in the prompt it would fail with that error.

jinkaleo

Hi Lalitha

I am new to Cognos and JS, finally you could able to achieve default value for the prompt? Can you please share sample script?

Thanks,
Chandra.