This Polarion extension provides additional functionality which is not implemented in standard Polarion API for some reason.
Important
Starting from version 2.0.0 only latest version of Polarion is supported. Right now it is Polarion 2512.
Polarion project does not support setting custom fields out of the box. This API extension can be used to solve this problem.
This API can be called using REST API and in Velocity Context.
The latest version of the extension can be downloaded from the releases page and installed to Polarion instance without necessity to be compiled from the sources.
The extension should be copied to <polarion_home>/polarion/extensions/ch.sbb.polarion.extension.api-extender/eclipse/plugins and changes will take effect after Polarion restart.
Important
Don't forget to clear <polarion_home>/data/workspace/.config folder after extension installation/update to make it work properly.
- Development Guide - Comprehensive guide for setting up development environment and contributing to this project
- Contributing Guidelines - Guidelines for contributing to this project
- Coding Standards - Coding standards and best practices
- Release Process - Information about the release process
This extension provides REST API. OpenAPI Specification can be obtained here.
Get version:
#set ($version = $customFieldsProject.getVersion())
#if ($version)
API Extender version = $version
#endor
#set ($version = $globalRecords.getVersion())
#if ($version)
API Extender version = $version
#endGet custom field value:
#set ($field = $customFieldsProject.getCustomField('elibrary', 'custom_field'))
#if ($field)
$field.getValue()
<br>
#endGet global record value:
#set ($field = $globalRecords.getRecord('record_name'))
#if ($field)
$field.getValue()
<br>
#endDue to Polarion limitations we are not able to save custom fields in Live Report Page using Velocity, but we can use JavaScript for this.
Set custom field value:
<input id='cfp_project' type='text' value='elibrary' name='project'/>
<input id='cfp_key' type='text' value='custom_field' name='key'/>
<input id='cfp_value' type='text' value='custom_value' name='value'/>
<script>
function save_project_custom_field() {
const project = document.getElementById('cfp_project').value;
const key = document.getElementById('cfp_key').value;
const value = document.getElementById('cfp_value').value;
const requestBody = (value === null || value === "") ? "" : JSON.stringify({'value': value});
fetch('/polarion/api-extender/rest/internal/projects/' + project + '/keys/' + key, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: requestBody
})
.then(response => {
if (response.ok) {
return "Saved!"
} else {
return response.text()
}
})
.then(text => {
alert(text)
});
}
</script>
<button onclick='save_project_custom_field()'>Save</button>Set global record value:
<input id='record_key' type='text' value='record_name' name='record_name'/>
<input id='record_value' type='text' value='record_value' name='record_value'/>
<script>
function save_record() {
const key = document.getElementById('record_key').value;
const value = document.getElementById('record_value').value;
const requestBody = (value === null || value === "") ? "" : JSON.stringify({'value': value});
fetch('/polarion/api-extender/rest/internal/records/' + key, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: requestBody
}).then(response => {
if (response.ok) {
return "Saved!"
} else {
return response.text()
}
}).then(text => {
alert(text)
});
}
</script>
<button onclick='save_record()'>Save</button>Note that internal API in URL should be used.
Get custom field value:
#set($projects = $projectService.searchProjects("","id"))
#foreach($project in $projects)
#set($projectId = $project.id)
#set($field = $customFieldsProject.getCustomField($projectId, 'custom_field'))
#if ($field)
$projectId custom_field = $field.getValue()
<br>
#set($field = false)
#end
#endGet global record value:
$globalRecords.getRecord('record_name')Set custom field value:
$customFieldsProject.setCustomField('elibrary', 'custom_field', 'new_value')Set global record value:
$globalRecords.setRecord('record_name', 'record_value')This extension includes several velocity tools to facilitate development and maintenance.
Sort a map by its values in ascending or descending order:
#set($sortedMap = $collectionsTool.sortMap($unsortedMap, true))Wrap given list of objects into a IPObjectList:
#set(list = $collectionsTool.convertArrayListToWeakPObjectList($workItems))Extract regex matches in the given text, returning the matches and their respective groups:
#set($matches = $regexTool.findMatches('(\d+)', "test123and456"))