Skip to main content
Skip table of contents

How to use the Jira Expression API to calculate dependant field values

TLDR: How to Store External Asset Platform Field Values in a Text Field for Better Integration with Dashboards

Using an External Asset Platform field type in Jira can have its limitations, especially when integrating with dashboard widgets. To address this issue, you can create a custom solution that writes the value of the selected asset into a separate text field. This will make it easier to work with in Jira.

Prerequisites:

  1. An external asset platform field (e.g., customfield_10083)

  2. An target text field

Data Source

Create a new data source of type Local Jira. Modify the URL to call the Expression API as follows:

NONE
.../rest/api/3/expression/eval

Add the JIRA expression with a variable in the body:

JSON
{
    "expression": "issues.map(i => {
        length = i.customfield_10083?.length || 0;
        if (length > 1) {
            return { fallback: 'MULTIPLE' };
        } else if (length == 1) {
            return { asset: i.customfield_10083[0]};            
        }else {
            return { fallback: 'EMPTY' };
        }
    })",
    "context": {
        "issues": {
            "jql": {
                "query": "id={ID}",
                "maxResults": 1
            }
        }
    }
}

The id={ID} variable will be used later to select the current issue, ensuring the expression runs only for a single issue.

The expression will analyse the length of the external asset platform field and either return MULTIPLE, EMPTY or the asset itself.

Test Connection

Dependant Field

Create a new Dependant Field and select the data source we have just created and enter $.issue.id into the ID variable of the data source. This should already show you a result for the current issue in the selected context.

The asset object doesn't return the label of the asset, so use a helper function to retrieve it and use the fallback value for multiple or empty assets.

CODE
{ GET_EXTERNAL_ASSET_LABEL(( $.value[0].asset )) || $.value[0].fallback}

Dependant Field Config

With these steps, you have successfully created a custom solution to store External Asset Platform field values in a text field, allowing for better integration with JIRA dashboards.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.