Unsupported
Thumb_plugin

Script Fields

 Automatically calculates the value of a Work Item field based on values of other fields.

Description

share this page via facebook share this page via LinkedIn share this page via Twitter share this page via Google+ share this page via email More sharing services

Features

  • Automatically fills fields of a Work Item by calculating the value with a script written in JavaScript or Groovy.
  • Content of the calculated field can be based on any other field(s) of the same Work Item.
  • Supports different calculated fields per Work Item type.
  • Supports any number of calculated fields.
  • The calculated field will be automatically updated whenever a Work Item is changed.
  • Includes a Job that forces update of the calculated field (required when the configuration or the script changed).
  • Easy configuration using a Wiki page.

Limitations

  • Calculation can only access content of the same Work Item. Access to nested objects (e.g. comments) is limited.
  • Changes to the calculated field won't appear in the history.
 

Installation

  1. Install the  scripting extension: /polarion/extensions/extension.jsp?extension=PE-1 (This step is not needed when using Polarion 2015 and newer)
  2. Copy folder com.polarion.alm.extensions.scriptfield to <Polarion Installation>/polarion/extensions
  3. Java 8 specific configuration - for run on Java 8, the following Java settings needs to be applied in polarion.ini (Windows) or config.sh (Linux):

    -Dosgi.parentClassloader=ext
  4. Restart Polarion.


Configuration


To configure the extension create a Wiki page called script-field-config in the default wiki space.
You can either create this page on global level, to define calculated fields that are used in every project or on project level to define calculated fields that are only used in one project.
 

Configuration Syntax

 
scriptfield.<field id>.<property name>=<property value>
or
scriptfield.[<type id>]<field id>.<property name>=<property value>
 
  • <type id>: ID of the Work Item type for which the property is defined.
  • <field id>: ID of the field for which the property is defined.
  • <property name>: Name of the property.
  • <property value>: Value of the property.
There are two properties with a special meaning:
  • script: Defines the file name (relative to the script folder (<Polarion Installation>/scripts by default) of the script to run.
  • engine: Defines the name of the scripting engine to use. Defaults to JavaScript. Use groovy as value to run a Groovy script.
In the script, all properties are available as variables. The name of the variable is the name of the property, the value the string value of the property.
 

Configuration Example

 
scriptfield.[requirement]cost.script=cost.js
scriptfield.[requirement]cost.pricePerManhour=50
 
The configuration will run the script cost.js whenever a (requirement) Work Item is changed to calculate the field cost.
 
A variable called pricePerManHour with the value "50" will be available in the script.
 
 

Job Configuration

Usually the script fields are only updated when a Work Item is changed. However, if you changed the configuration or the script and want to ensure that all Work Items are updated according to the changed settings you should use the update job.
 
To be able to use the Job you have to configure it in the Scheduler configuration of Polarion (Global Administration > Scheduler).
Add following job definition:
 
 <job name="Update Script Fields Global" id="update.script.fields" disabled="true" scope="system">
  </job>
 
The job will have to look at every Work Item to determine if it has to be updated.
If you have a Polarion installation with many Work Items, you should consider configuring the job for only specific projects by adjusting the scope accordingly.
 


Writing Scripts


As mentioned earlier every property defined in the configuration will be available in the script.
 
Additionally there is a workItem variable which stores the Work Item.
Unfortunately the type of Work Item is not the type from the open API, but a low-level type called IDataObject.
 
The relevant methods of this type are:
  • Object getValue(String fieldId) to get the value of a field.
  • Object getCustomValue(String customFieldId) to get the value of a custom field.
  • Set<String> getKeySet() to get available field ids.
  • Set<String> getCustomKeySet() to get available custom field ids.
To work with the value of get*Value(...) you need to know what type you are dealing with.
The best way to find out is to use a simple test script that fills the type of a  field value in a string field, e.g. the title. To do this you could use following configuration:
 
scriptfield.title.script=test.js
 
And store following scipt as tets.js in your scripts directory:
 
workItem.getValue("author").getClass().toString();
 
 

Example

 
Take a look at /polarion/extensions/extension.jsp?extension=PE-200 this example calculates the cost of a requirement from the Initial Estimate of a Work Item.
 

 

What's New in Version 1.0.3

Updated October 2015

Streams for reading scripts are properly closed after each script invocation.

-        Version increased to 1.0.3

 

Information

Vendor Ben Gleei (Siemens PLM)
Published Version 1.0.3 - October 2015
Categories
Products
Price Free
260 Downloads
Unsupported Extension This extension is not supported by Siemens PLM.
Requirements
  • Polarion version 2010+
  • Scripting extension (included in Polarion version 2015+)
  • Related Extensions