---
title: "PCF - SIL Script Custom Field"
canonical: "https://support.appfire.com/space/PSJ/1589020045/PCF%20-%20SIL%20Script%20Custom%20Field"
format: markdown
---
> Macro (aura-html)

> Macro (button-handy)



![PCF - SIL Script custom field configuration page - General tab](media://8d84e98c-f205-4ef1-8813-1a740ff23bea)

3. On the *General*** **tab, set the following:

| **Setting** | **Options** |
| --- | --- |
| Choose display format from the **Value formatted as** drop-down list. | - **Script Template**: Formats the output using a custom template
- **Date**: Displays the output as a date
- **Date Time**: Displays the output as a date with time |
| Select a **Refresh interval** | - **Always**: Recalculates whenever the value is needed
- **Never**: Uses the initially calculated value
- **Specify interval**: Recalculates after a set time period<br>> 📝 **Important note on refresh behavior:**
> 📝 
> 📝 The field recalculates only when its value is needed, and the interval has passed, not automatically at each interval. For example, with "Always" refresh, when searching for issues by a field that shows the current minute, you must search for the last displayed value rather than the current minute. |

4. On the *Scripts* tab, set the following:
  1. Enter your SIL script to compute the field's value. This script determines how the field's value will be calculated.
  2. (Optional) Configure a template (see [SIL Template Language](https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15488414)). Use this to format how the calculated value is displayed.
5. Click **Save**. The script is now associated with the current custom field.
  

---

## How the field displays

Here's how the custom field appears in your Jira instance. The value returned by the script will be displayed as the field's value. 

> 📝 **Important notes on script limitations:**
> 📝 
> 📝 - The script is readonly; changes to issue values won't be saved.
> 📝 - While the field appears in both **View** and **Edit** screens, it remains read-only.
> 📝 - Some functions may have side effects.

#### Display example 1

The screenshots below illustrate the PCF - SIL Script Custom Field displayed on edit issue and view issue** **screens in Jira.

![PCF - SIL Script Custom Field on edit issue screen](media://5fa739e2-df7b-4781-a716-ba11ceb8049b)

![PCF - SIL Script Custom Field on view issue screen](media://882ff060-d44c-4d92-ad97-752c1872d212)

#### Display example 2

This example illustrates how the template script modifies how the value of the custom field is displayed. 

| **Script** | **Script configuration screen** | **Field displayed on View screen** |
| --- | --- | --- |
| If you enter this script in the `SILSCRIPT` file:<br>```
return currentDate();
``` | ![Scripts tab on PCF-SIL Script custom field configuration page with selected SILSCRIPT.](media://28a3ce6a-fe91-43f0-8167-6db22ad4fd60) | This is how the field value displays:<br>![PCF-SIL Script Custom Field on view issue screen without template.](media://04c64a53-14ba-4e2f-b611-b6c4e73e912c) |
| If you add this script in the `TEMPLATE` file:<br>```
<html>
    <head>
        Current date is:
    </head>
    <body>
        <p style="color:red;">$currentDate()$</p>
    </body>
</html> 
``` | ![Scripts tab on PCF-SIL Script custom field configuration page with selected TEMPLATE.](media://41b09e0f-7d62-48a2-aaf8-003af3060d58) | This is how the field value displays<br>![PCF-SIL Script Custom Field on view issue screen with template.](media://58fce38f-b7a6-415e-9e12-7294e511de88) |


---

## Examples

| **Example** | **Sample script** | **Sample display output** |
| --- | --- | --- |
| Display Issue Age | This script calculates and displays how long an issue has existed.<br>```
interval age = currentDate() - created;
return "This issue is " + age + " old";
``` | “This issue is 10w 1d 1h 5m 26s old” |
| Display the number of substacks for a ticker | This script counts and displays how many subtasks are associated with an issue.<br>```
number noSubtasks = size(subtasks(key)); 
return "This issue has " + noSubtasks + " subtasks";
``` | “This issue has 5 subtasks” |
| Display average age of subtasks | This script calculates and displays the average age of all subtasks for an issue.<br>```
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));
``` | “Average age of subtasks is 4d 12h 45m” |
| Display results from database | This script retrieves city names from a database based on a specific region.<br>```
//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'");
``` | Returns a list of cities from the Bucharest region, for example: "Sector 1, Sector 2, Sector 3" |
| Display duration in current status | This script calculates and displays how long an issue has been in its current status. If there's no status history, it shows the total issue age.<br>```
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);
``` | “Current issue has been In Progress for 2d 4h 30m” |
| Display unique status changes count | This script counts how many different statuses an issue has gone through in its lifecycle.<br>```
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);
``` | “3” (indicating the issue has been in three different statuses) |
| Display all historical assignees | This script lists all users who have ever been assigned to an issue, including the current assignee.<br>```
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;
``` | “John Smith, Jane Doe, Mark Wilson" (a list of all users who have been assigned to the issue) |

---

## Configure search settings for your PCF - SIL Script custom field

1. Locate your PCF - SIL Script Custom Field on the **Custom fields** page and click **Edit details**.
2. Select a **Search Template **compatible with your field's return value type.
3. Click **Update**.

> ✅ After the update, reindex your Jira instance to ensure search functionality works correctly.

4. Test the search functionality.

![Search box with search results displayed in Jira.](media://c4506f0d-413e-4ee5-b087-e2bb3d837d28)

> ℹ️ To learn more about the search functionality, see the Jira [Searching for Issues](http://confluence.atlassian.com/display/JIRA/Searching+for+Issues) tutorial.