---
title: "Cascade asset custom field"
canonical: "https://support.appfire.com/space/AIP/30900244/Cascade%20asset%20custom%20field"
format: markdown
---
> Macro (aura-html)

This document explains how to configure asset custom fields to support the cascading fields feature in Jira Service Management. Cascading fields allow you to restrict options in a child field based on the selection in a parent field. 

## Example

In this example, we will create 5 asset custom fields with the following relation:

![image](media://dd6f76b2-b309-4c62-a88e-1544886baed8)

> 📝 **Important:**
> 📝 
> 📝 - This feature is not supported for Jira's inline edit. All fields involved must be on the *Edit* or *Create* screen. You can create a workflow screen to edit these fields.
> 📝 - Linked assets are not supported for cascade asset fields.
> 📝 - This is a client-side feature, meaning the logic runs in the user's browser.

## Instructions

### 1. Create asset custom fields

Create five asset custom fields (`Make CF`, `Model CF`, `Model colour CF`, `Model variant CF`, `Model variant extra CF`) and set screens. 

![image-20240527-200845.png](media://23da7467-1b7d-477a-923a-63bf32d43bcc)

### 2. Create Asset Types and reference type attributes

Create five Asset Types and attributes:

**2.1 Asset Type: **`Make AT`

Create an Asset Type called `Make AT`.

![image](media://4a8b3b12-19dc-4b1f-9590-bd0700b3ee77)

**2.2 Asset Type: **`Model AT`

Create an Asset Type called `Model AT`.

![image](media://ed72340f-064e-4662-b344-fc31ea50a091)

Create an attribute called `Make attr` and add it to the `Model AT` Asset Type.

![image](media://dd44a209-a6e8-4da8-b182-1c1ee1d76807)

**2.3 Asset Type: **`Model colour AT`

Create an Asset Type called `Model colour AT`.

![image](media://c1e1b18a-7e3f-45b1-97c8-f5fb9a1e0ad2)

Create an attribute called `Model attr` and add it to the `Model colour AT` Asset Type.

![image](media://b6969c99-6792-46e2-8602-e8b203b66999)

**2.4 Asset Type: **`Model variant AT`

Create an Asset Type called `Model variant AT`.

![image](media://97203a70-898a-42a9-a57f-070935f02e8d)

Add `Model attr` *(which was created in the previous step)* to the `Model variant AT` Asset Type.

**2.5 Asset Type: **`Model variant AT`

Create an Asset Type called `Model variant extra AT`.

![image](media://5dad79b2-76aa-43cd-97a1-72d737de0e90)

Create an attribute called `Model variant attr` and add it to the `Model variant extra AT` Asset Type.

![image](media://c3305df7-6f6c-4137-953f-c3c1929baf59)

### 3. Create asset filters

Create four asset filters for child custom fields. Save them as System filters.

![image](media://af0dd985-5deb-4938-ab66-fcec9ca8da21)

**3.1 Asset filter: **`Model CF`

**Parent custom field ID:** 10300 *(This is *`Make CF`* custom field ID. You can find it at ****Assets**** > ****Settings**** > ****Custom Fields Configuration**** page)*

**Search fields: **

- Asset type: Model colour AT
- Make attr: **Function =** referenceAssetByType("Make AT","asset.id","$customFieldAssetIds(10300)")

`Make attr`** **search details:

![image](media://7bb1d132-906a-48d7-a3e6-89f8a53c7b85)

**3.2 Asset filter: **`Model colour CF`

**Parent custom field ID:** 10301 *(10301 (This is *`Model CF`* custom field ID. You can find it at ****Assets**** > ****Settings**** > ****Custom Fields Configuration**** page)*

**Search fields: **

- Asset type: Model colour AT
- Model attr: **Function =** referenceAssetByType("Model AT","asset.id","$customFieldAssetIds(10301)")

**3.3 Asset filter: **`Model variant CF`

**Parent custom field ID:** 10301 *(10301 (This is *`Model CF`* custom field ID. You can find it at ****Assets**** > ****Settings**** > ****Custom Fields Configuration**** page)*

**Search fields: **

- Asset type: Model variant AT
- Model attr: **Function =** referenceAssetByType("Model AT","asset.id","$customFieldAssetIds(10301)")

**3.4 Asset filter: **`Model variant extra CF`

**Parent custom field ID:** 10301 *(10301 (This is *`Model CF`* custom field ID. You can find it at ****Assets**** > ****Settings**** > ****Custom Fields Configuration**** page)*

**Search fields: **

- Asset type: Model variant AT
- Model variant attr: **Function =** referenceAssetByType("Model variant AT","asset.id","$customFieldAssetIds(10303)")

### **4. Asset custom fields configuration**

Navigate to the **Assets** > **Settings** > **Custom Fields Configuration** page, and configure each asset custom field.

![image](media://5d25769a-a430-44bf-8b00-59e4d894ab2d)

**4.1 Asset custom field configuration: **`Make CF`

- **Custom field contents:** Asset Types of `Make AT`
- **Child custom field for cascade field: ** `Model CF`
- **Callback Javascript function name to be called on custom field value change: **
  - window.assetOnChange_customfield_10300_01
  - This is optional. We will provide this JavaScript function with ScriptRunner Behaviours.

**4.2 Asset custom field configuration: **`Model CF`

- **Custom field contents:** Asset Filter of `Model CF`
- **Child custom field for cascade field: ** `Model colour CF` and `Model variant CF`
- **Callback Javascript function name to be called on custom field value change: **
  - window.assetOnChange_customfield_10301_01
  - This is optional. We will provide this JavaScript function with ScriptRunner Behaviours.

**4.3 Asset custom field configuration: **`Model colour CF`

- **Custom field contents:** Asset Filter of `Model colour CF`
- **Child custom field for cascade field: ** Empty
- **Callback Javascript function name to be called on custom field value change: **
  - window.assetOnChange_customfield_10302_01
  - This is optional. We will provide this JavaScript function with ScriptRunner Behaviours.

**4.4 Asset custom field configuration: **`Model variant CF`

- **Custom field contents:** Asset Filter of `Model variant CF`
- **Child custom field for cascade field: ** `Model variant extra CF`
- **Callback Javascript function name to be called on custom field value change: **
  - window.assetOnChange_customfield_10303_01
  - This is optional. We will provide this JavaScript function with ScriptRunner Behaviours.

**4.5 Asset custom field configuration: **`Model variant extra CF`

- **Custom field contents:** Asset Filter of `Model variant extra CF`
- **Child custom field for cascade field: ** Empty
- **Callback Javascript function name to be called on custom field value change: **
  - window.assetOnChange_customfield_10304_01
  - This is optional. We will provide this JavaScript function with ScriptRunner Behaviours.

### **5. Callback functions on asset custom field’s value change event (Optional)**

Open ScriptRunner's **Behaviours** and add a new configuration. This step is optional and not required for cascade fields.

When the color field is changed, we’ll hide/show the Country combo box. For the sake of simplicity, we do not hide initially, but we should for a production example.

Other fields log to the console only.

![image](media://fbcc2819-6c2f-4234-801c-fdd1613e8c3d)

In the Initialiser script, we attach JavaScript to five custom fields. Then, we insert the JavaScript into the custom field’s help text. 

```groovy
def trackedAssetFieldId = "customfield_10302";
def cfTargetFieldId = "customfield_10143";

String js = """

    window.assetOnChange_${trackedAssetFieldId}_01 = function (cfId) {
        console.log(' assetOnChange_${trackedAssetFieldId}_01 - cfId:', cfId);
        const container = AJS.\$("#${cfTargetFieldId}").parent().parent();
        if (AJS.\$("#customfield_" + cfId).val()) {
            container.show();
        } else {
            container.hide();
        }
    }

    window.assetOnChange_customfield_10300_01 = function (cfId) {
        console.log('customfield_10300 fnc. cfId:', cfId);
    }

    window.assetOnChange_customfield_10301_01 = function (cfId) {
        console.log('customfield_10301 fnc. cfId:', cfId);
    }

    window.assetOnChange_customfield_10304_01 = function (cfId) {
        console.log('customfield_10303 fnc. cfId:', cfId);
    }

    window.assetOnChange_customfield_10304_01 = function (cfId) {
        console.log('customfield_10304 fnc. cfId:', cfId);
    }


""".stripMargin();


String currentHelpText = getFieldById(trackedAssetFieldId).getHelpText();
def cf = getFieldById(trackedAssetFieldId);
cf.setHelpText(currentHelpText != null ? currentHelpText : "" + "<script>"+js+"</script>"); 

```

### 6. Testing

**6.1. Create test data**

Create several assets and set reference assets.

![image](media://bc574ca8-9295-4405-8675-f2ed5f56095b)

**6.2. JSM customer portal test**

When all the asset types have sample data, we can play with **Make** and **Model** options. This works for Jira as well. You should see something like this below.

---

That’s all! If something is broken, please review all the steps and compare them with your configuration.