Velocity – the quick way, to realize small customizings in Polarion.

In this Part, I will explain the basic functionalities of Velocity in Polarion. Additional information about APIs will be introduced in other posts.

First of all: What can I do with Velocity?

  • Configure report widgets even more detailed
  • Create your own widgets
  • Render information dynamically in documents
  • … short: Code that I can access the Polarion API with and customize reports & documents.

Where can I use Velocity?

  • Script blocks in report pages
  • Velocity widgets
  • Classic wiki pages
  • Classic wiki blocks in documents
  • Administration (e.g. Test Execution Form)

I want to show the capabilities of Velocity at the example of a code block in a report page. There you can simply repeat, what I am writing.

Go to Polarion and create a new „Live Report Page“. Then add a new widget of the type „Script – Block“ to it. In this you can write Velocity code and try things.

Attention: You might not be able to use the latest Velocity version here.

For you, I will mention the most important functions:

  1. Declare variables:
    #set($variableInteger = 1)
    #set($variableString = „abc“)
    #set($variableList = [])
    #set($x = variableList.add($e))
  2. Loops:
    Foreach:
    #foreach($e in $elements)
    doSth
    #end
  1. More Loops
    ____
    How to create a „for-loop“:
    #set($start = 1)
    #set($end = 5)
    #set($range = [$start..$end])
    #foreach($i in $range)
    doSth
    #end
  1. Conditions: IF / Else
    #if($var == „XYZ“)
    doSth
    #else
    doSthElse
    #end
  1. Macros / Functions:
    Important: Macros must be defined, before they are called!
    #macro(nameOfMacro $variable1 $variable2)
    doSth
    #end
  1. Commenting:
    ## This is a comment
  2. Find out class of an object
    By using the attribute „.class“ you can find out, from which class an object is.

8. Important: The Object Factory allows to use things like a Map, although velocity itself doesn’t provide something like that. You can access it in the velocity context via „$objectFactory“. (Might not work in classic wiki content/pages)

I hope this could give you a basic overview of the most important functions in Velocity.

Basics: Velocity

Beitragsnavigation


4 Gedanken zu „Basics: Velocity

    1. Hi Chris,

      great to hear you like the blog!

      If I understand correctly, then the mehods that you find in the Polarion API are exactly that. So yes, Polarion supports methods. Otherwise you wouldn’t be able to do e.g. $trackerService.queryWorkItems().

      Best,
      Dude

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert