Advanced Reporting: Scripted Page Parameters

Most widgets can use page parameters so that users can configure them without going into the edit mode of the report page. But some widgets have the additional capability to utilize “scripted page parameters” that can be used to add scripted logic to widget parameters.

… So what do I mean by it?

Let me explain it at the example of the Multilevel Traceability Widget. This widget has “widget parameters” like e.g. “Display Test Execution Results from Query”.

You could enable your users to set this parameter without going to the administration by hovering over the gear symbol and then click “save”.

This parameter can then be added to your page parameter widget. (See my other post about the basics of page parameters)

But now the user would still have to enter the query of the relevant test cases manually.

If you want your users to simply select a release and then automatically get the correct query for all relevant test runs – that’s where you would need the “scripted page parameters”.

How to create scripted page parameters?

You can find the official description in the chapter 7.2 of the widget sdk guide:

To define the logic and the page parameter you have to go into the “page script” of the report page.

There you can create a logic with velocity to get the test run query you would like. To get a query for all test runs in a custom field of a release you could use a code similar to this:

## Declare Variables
#set($projectId = $page.reference.projectId())
##set($projectService = $trackerService.getProjectService())
#set($project = $projectService.getProject($projectId))
#set($escapeQuote = "$esc.q")
## Get selected release
#set($release = $trackerService.getWorkItem($page.reference.projectId, $pageParameters.release.singleValue().id))

## Create List with relevant Test Run IDs and a Test Run Query
#set($testRunsIdList = [])
#set($testRunQuery = "")
#set($count = 0)
#foreach($testRunEnumOpt in $release.getCustomField("testRuns"))
	#set($x = $testRunsIdList.add($testRunEnumOpt.getId()))
	#if($count == 0)
		#set($testRunQuery = $testRunQuery.concat("(id:$escapeQuote$testRunEnumOpt.getId()$escapeQuote)"))
		#set($testRunQuery = $testRunQuery.concat("OR (id:$escapeQuote$testRunEnumOpt.getId()$escapeQuote)"))
	#set($count = 1)

This code will result in a string that contains the query for all test runs in the custom field of a release.

Now we can create the scripted page parameter. This is similar to creating widget parameters for widgets. For a simple string value you can use this:

$!scriptedPageParameters.put("testRunQuery", $factory.string("Test Run Query").value($testRunQuery).build())

The parameter we just created can then be selected in the widget parameters of the multilevel trace widget:

And if we now select a release in the report page, we get the test runs according to the selected release automatically filled in the widget parameter.

Published by PolarionDude

Dude who does Polarion - if Polarion would be a verb.

One thought on “Advanced Reporting: Scripted Page Parameters

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with
Get started
%d bloggers like this: