Return viewparameter captions at ready state

Hello Everyone,


Can someone please share script that will return the current captions saved in a specific viewparameter at the ready state of dashboard.


Much appreciated

Could you expand on what you mean by 'captions'?

This may get you started…but you’ll have to adapt it for your needs and it requires that the view parameter be connected to a parameter hierarchy.


Script to read parameter values and put them in an array (for my use case this script is in the Parameter Value Changed action of the parameter hierarchy – your use case may require putting it elsewhere):


var count = [Script Name of Your Parameter Hierarchy].control.parameterValue.values.length;

var baseViewService = this.getService("BaseViewService");

var hierarchyService = this.getService("HierarchyService");


var allValues = new Array();


for(i=0;i<count;i++){

var v = [Script Name of Your Parameter Hierarchy].control.parameterValue.values[i];

var uniqueName;

//The line below will likely need to be modified as my use case required only the first layer of a multi-layer hierarchy

uniqueName=v.uniqueName.substr(0,v.uniqueName.indexOf("."));

allValues.push(uniqueName);

}

//Now do whatever you want with the array


Credit to Jay Gong with Dundas BI Support for patiently walking me through this and providing the bulk of this code.

Ooh, I just noticed that Bobby Byrne responded to this topic. Do whatever he says.

Sorry for the slow response. My original intent was see if it was possible to do without a parameter hierarchy. It appears that is is best practice to have a parameter hierarchy for each view parameter.


, by captions, I mean the string 'caption' that is attached to my numeric data value. All of my dimensions are integer based for better filtering performance. I create hierarchies with string captions.

In code example, it returns the numeric value of the parameter. I was able to put this code together to retrieve the caption string from the parameter hierarchy.


var filterchoice = [];
var vlength = [Script Name of Your Parameter Hierarchy].control.parameterValue.values.length;

for (i = 0; i < vlength; i++)
{
filterchoice.push ([Script Name of Your Parameter Hierarchy].control.parameterValue.values[i]._originalHierarchyMember.caption);
};
label1.labelText=filterchoice.join(", ");


So now that I have that worked out, I need to change the selected item in a drop downlist component based upon the value of the parameter heirarchy. I have found how get the current value, but not how to change the selected item. Any pointers there would be appreciated.

I understand you have a solution on hand now, Doug. Could you share it here?

Thanks to Abdi Elmi for this code. I am still trying to understand the js structure, but it does correctly return the caption. What I want to work on next is to convert this to a function that I can call in other scripts, ie label1.labeltext = getparamcaption(VegatableGroupviewparameter)


var analysisStructureID = "49326efe-0cf6-425b-b4e0-cbdbd0a0f261";

var hirearchyService = this.getService("HierarchyService");
var viewParamters = this.getService("BaseViewService").currentView.control.viewParameters;

var VegatableGroupviewParameter = viewParamters.filter(function(vp){
return vp.name == "VegatableGroupviewParameter";
})[0];

var getOptions = {
hierarchyUniqueName: VegatableGroupviewParameter.parameterValue.values[0].hierarchyUniqueName,
levelUniqueName: VegatableGroupviewParameter.parameterValue.values[0].levelUniqueName,
memberUniqueName: VegatableGroupviewParameter.parameterValue.values[0].uniqueName
};

var VegatableGroupviewParameterMember = hirearchyService.getMember(analysisStructureID, getOptions).done(function(member)
{
var parametercaption = member.caption;
alert("caption " + parametercaption);
}
);