Skip to end of banner
Go to start of banner

PCF - SIL Script Custom Field

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 42 Next »

Contents

Before using SIL Script Custom Field check out the Simple Issue Language documentation for a better grasp of SIL usage and capabilities.

Configuring PCF - SIL Script custom field

  1. After you create the field, click the Configure link for this field. You will see the page like the following example:



  2. Click the EditSIL Script link to see the SIL editor.



  3. Click Save, and the script is associated with the current custom field.



  4. The value returned by the script will be the value of the custom field.


The script is read-only. You must avoid changing any issue values in the script. In fact, you may change the issue variables BUT they will not be changed (issue will not be saved). However, routines may have side effects.

Thread Local Caching

If you are not fully aware of what this implies, it is recommended that you leave the option off.

Because multiple calls to get the value of a SIL Script Custom Field for a certain issue are inevitable, we implemented an option to generate the value only once per HTTP request. This can improve performance, but might have some side effects.
For instance, if the value is generated before some other values it depends on are modified, the result might not reflect latest updates.

Using PCF - SIL Script custom field

Go to an issue and this is how the value of the field is the value returned by the script.


Examples

Issue Age

interval age = currentDate() - created;
return "This issue is " + age + " old";

Number of subtasks

number noSubtasks = size(subtasks(key)); 
return "This issue has " + noSubtasks + " subtasks";

Average Issue Age

date now = currentDate(); // just to make sure we use the same reference date
string [] subtasks = subtasks(key);
interval age;
for(string task in subtasks){
 age = age + (now - %task%.created);
}
return "Average age of subtasks is " + (age / size(subtasks));

Results from Database

//select the city from the specified region
return sql("TestSQL", "select city from cities c, district d, region r where c.iddistrict=d.id and d.idregion=r.id and r.region='Bucharest'");

Status Age

string field_name = "status";
string[] field_history = fieldHistory(key, field_name);
number n = arraySize(field_history);
date startDate; 
if (n > 0) {
 startDate = arrayGetElement(field_history, n - 2);
 return "Current issue has been " + status + " for " + (currentDate() - startDate);
}
return "Current issue has been " + status + " for " + (currentDate() - created);

Issue Statuses Count

string[] statuses;
string[] statusHistory = fieldHistory(key, "status");
for(number i = 1; i < size(statusHistory); i = i + 2) {
 string statusStr = getElement(statusHistory, i);
 statuses = addElementIfNotExist(statuses, statusStr);
}
return size(statuses);

Issue Assignees

string[] assignees;
assignees = addElementIfNotExist(assignees, userFullName(assignee)); 
string[] assigneeHistory = fieldHistory(key, "assignee"); 
for(number i = 1; i < size(assigneeHistory); i = i + 2) {
 string assigneeName = userFullName(getElement(assigneeHistory, i));
 assignees = addElementIfNotExist(assignees, assigneeName); 
}
return assignees;

Search Issues

  1. If you want a Sil Script Custom Field to be searchable you must select a Search Template for that custom field.

2. If the custom field already exists, in Administration->Custom fields, click Edit for the desired custom field, and choose the proper Search Template for your custom field according the value type returned by it.

3. If you are about to add a new Sil Script Custom Feld, you can choose the Search Template at the step 'Create Custom Field - Details (Step 2 of 2)'.

Perform a re-index
After changing the Search Templates for all the custom field that you want, perform a re-index in Jira for the search to work fine.

4. After a searcher has been set for the Sil Script Custom Field, you can perform a search for all issues containing the desired value for that custom field.

5. For a detailed explanation on searching issues in Jira, you can check the Searching for Issues tutorial from the Jira documentation.

  • No labels