Behavior Script with Insight Object

Naman Mandli
Contributor
March 25, 2021

Hello,

I am creating a behavior script using ScriptRunner and want to hide some field-based on selected value which is of an Insight object type.

For example: 

if Native value(insight field) = XYZ then hide a field, if not XYZ =>do not hide the field.

This behavior is not working for me. Can someone please help?

import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor

def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)

def monthlyMaintenance = getFieldByName("Is this for monthly network maintenance?");
//def tid = getFieldByName("TID and Business Service");
//============================

monthlyMaintenance.setHidden(true);
def tid_Insight = getFieldById("customfield_29540");
def tid_val = tid_Insight.getValue().toString();
def bs_Insight = getFieldById("customfield_29541");
def bs_val = bs_Insight.getValue().toString();

//============================

//ArrayList cascadeValueStore = tid.getValue() as ArrayList

//log.debug("cascadeValueStore----" + cascadeValueStore)
log.debug( "monthlyMaintenance----"+ monthlyMaintenance.getValue())

if (issueContext.projectObject.key == "ITPPM" && issueContext.issueType.name == "Change Log"
// && cascadeValueStore[0] =="INFR" && cascadeValueStore[1] == "Network"){
// && cascadeValueStore.contains("TO") && cascadeValueStore.contains("Systems Monitoring")){
// && tid_val.contains("IAT-1749431") && bs_val.contains("IAT-1806913")){
&& tid_val.contains("TO") && bs_val.contains("Systems Monitoring")){ // only show monthlyMaintenance field if this condition match
monthlyMaintenance.setHidden(false);
}

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 26, 2021

Behaviours formField.getValue() on an insight field will return either a single Object Key, or an Array of Object Keys depending on whether the field allows multiple or not.

So you can either get the key for the object that you want to trigger your behaviours and hard code that, or programmatically retrieve an ObjectBean from the Insight API then retreive the attribute values to use in the behaviour logic.

Naman Mandli
Contributor
March 27, 2021

Thank you Peter. I am able to get the object value:

def tid_Insight = getFieldById("customfield_29540");
def tid_val = tid_Insight.getValue().toString();

But the behavior script is not able to capture events for Insight fields.

1. Selected customfield_29540 field which Insight field on behavior script screen

2. Implemented the above script. 

3. Based on the value of customfield_29540 filed it should show/hide another field. This part is not working.

 

Please help.

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2021

Newest versions of scriptrunner do fire behaviours scripts on insight field changes.

Though it doesn't yet from service desk portal screens.

Try to upgrade if you haven't in a while

Naman Mandli
Contributor
March 30, 2021

Thank you Peter. Let me try.

Suggest an answer

Log in or Sign up to answer