Cascade asset custom field
This page is about Assets & Inventory Plugin for Jira DC. Using Cloud? Click here.
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:
window.assetOnChange_customfield_xxxxx_01
) 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.
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
.
2.2 Asset Type: Model AT
Create an Asset Type called Model AT
.
Create an attribute called Make attr
and add it to the Model AT
Asset Type.
2.3 Asset Type: Model colour AT
Create an Asset Type called Model colour AT
.
Create an attribute called Model attr
and add it to the Model colour AT
Asset Type.
2.4 Asset Type: Model variant AT
Create an Asset Type called Model variant AT
.
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
.
Create an attribute called Model variant attr
and add it to the Model variant extra AT
Asset Type.
3. Create asset filters
Create four asset filters for child custom fields. Save them as System filters.
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:
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.
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
andModel 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.
In the Initialiser script, we attach JavaScript to five custom fields. Then, we insert the JavaScript into the custom field’s help text.
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.
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.