In this article
Domain
This script used to build up the domain for a parameter.
To enter the script editor, right-click an appropriate parameter in the Report Tree and select Script > Domain.
Without scripting, the domains for parameters are loaded in different ways depending on parameter type:
- Projects - connect the parameter to a question in a survey containing the project IDs that you want to load. Double-click the parameter to open the page where you can connect the project to a question.
- Questionnaire Elements - manually build a hierarchical structure of questionnaire elements from the parameter designer page (double-click the parameter to get there).
- Segments - do the same as for the questionnaire element except that you drag segments into the tree structure.
- String Response - connect the parameter to a question the same way as for the project parameters. This makes the domain implicitly load the answer list of that question.
If you use a domain script for a parameter, you override the default way of loading the domain. You have to do this loading explicitly from within the script.
The advantage is that you can then load the domain differently, for example depending who the user is and what other selections the user has made for other parameters. Typically, you can do this based on the user’s role or some other information from a database designer table relating user’s to elements in lists.
Projects Example:
To link one or more projects to a report, include a parameter to your report.
- Under parameter properties, select Type Project.
- Right-click on the parameter, and select Script.
- To include projects to your report, add the following script:
- In the GetProject method, include the id of your project.
- To use this parameter, include a List element in your report.
- Drag & drop the Questionnaire Elements Example project parameter.
- Create a new parameter and rename it for example p_questions.
- Right-click on it and select Script, then enter the following code:
var p : Project = this.confirmit.GetProject('pxxxxxxx');
parameter.Items.AddProject(p);
p = this.confirmit.GetProject('pxxxxxxx');
parameter.Items.AddProject(p);
The Questionnaire Elements can be used to include questions from a project into a drop-down menu. If you have several projects in your report, you can script which questions to display depending on the project selected in the project parameter (p_project).
if(state.Parameters.IsNull("p_project"))
return;
//Checks to see if a project has been seleced. If not, nothing is returned.
var pid : String = state.Parameters.GetProjectId("p_project");
var project : Project = confirmit.GetProject(pid);
//The project selected is defined
var questions : Question[] = project.GetQuestions();
parameter.Items.AddQuestions(questions)
//The questions in the project selected are included in the parameter.
If you do not wish to include OpenText and MultiOpen questions in the parameter, since these will not work in Aggregated Tables, the following code can be used instead of the last line; parameter.Items.AddQuestions(questions);
for(var i : int=0; i<questions.length;i++)
{
if (questions[i].QuestionType != QuestionType.OpenText && questions[i].QuestionType != QuestionType.MultiOpen)
parameter.Items.AddQuestions(questions[i]);
}
This script will iterate through the questions and check if they are QuestionType OpenText or MultiOpen. If not, they will be added to the questions parameter.
Mask
This script is used to mask the domain of a parameter. For these types of parameters you can add a mask script to mask the parameter domain for example based on other selections. This script is typically used when the original domain can be loaded using the default method, but the list of values need to be masked in some way. You can choose whether to use inclusive or exclusive masks, that is whether the keys you add to the mask are those that should be included in or excluded from the domain.
Note that Mask script only applies to project, segment questionnaire element and string response parameter types.
To enter the script editor, right-click an appropriate parameter in the Report Tree and select Script > Mask.
Masking a single-select parameter value:
mask.Access = ParameterAccessType.Exclusive; //This declares the mask excludes the code
{mask.Keys.Add('pie');} //Then the precode to be excluded is added
In this example, the chart type "Pie" has been masked.
The script can be expanded to check whether a condition is true before implementing the masking.
Masking single-select parameter values based on table cell values:
//------------Parameter Scripting MASK----------------//
mask.Access = ParameterAccessType.Exclusive;
if(report.TableUtils.GetCellValue('CA',1,1).Value==0) {mask.Keys.Add('1');}
if(report.TableUtils.GetCellValue('CA',2,1).Value==0) {mask.Keys.Add('GS1');}
//The above checks table CA, row 1 column 1, row 2 column 1 to see if the value is "0" before excluding the code
In this example, parameter values are masked based on table cell values.
Masking a parameter’s values based on another parameter's values:
var multiResponseA : ParameterValueMultiSelect = state.Parameters["p_Country"];
//Linking the Multi parameter the the MultiSelect class
var responseA : ParameterValueResponse;
//Creating a variable to hold the selected parameter responses
var country : String = "";
//An array to hold the precodes
//checking if there are any answers in the country parameter
if(multiResponseA != null)
{
for(var x : int = 0; x < multiResponseA.Count; x++) //running a for loop to go through answers
{
responseA = multiResponseA[x];
country += "'";
country += responseA.StringValue;
country += "'";
}
}
text.Output.Append(country);//printing the selected answers to screen
Filter Summary
This script is used to customize the filter summary label of a parameter. For some parameters it will make sense not to have one line in the filter summary for each parameter, for example if you use one parameter to choose which question to filter by, and another to select the filter values. In these cases you can choose to hide one of the parameters from the filter summary and customize your own label for the other one to have the filter on one line.
To enter the script editor, right-click an appropriate parameter in the Report Tree and select Script > Filter Summary.
Customize filter summary for filter:
if(state.Parameters.IsNull("p_filter_q") || state.Parameters.IsNull("p_filter"))
return;
var q : QuestionnaireElement = state.Parameters["p_filter_q"];
state.LoadParameterLabel("p_filter_q");
state.LoadParameterLabel("p_filter_a");
output.Append(q.Label + "(");
var first : boolean = true;
for(var r : ParameterValueResponse in a)
{
if(first)
first = false;
else
output.Append(", ");
output.Append(r.Label);
}
output.Append(")");