Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Behaviour based on preset value in SD form

Joel Batac December 22, 2022

Hi,

 I have a single-select field appName withs option BRI, CA, DM). And another single-select field ipName (options BRI 1, BRI2, CA 1, CA 2, DM 1 and DM 2)

I have 3 request types, namely BRI, CA and DM which have preset value for appName accordingly.

 If a user raise a request, for example for CA, I only want to show CA1 and CA 2 for ipName field drop down. Same for BRI and DM

 

Is this possible?

1 answer

1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 22, 2022

Hi @Joel Batac

This is a common question that has been asked several times in the community.

I will show you an example tested on the Service Desk. Below is the sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def appName = getFieldById(fieldChanged)
def appNameValue = appName.value.toString()

def ipName= getFieldByName('IP Name')

def customFieldManager = ComponentAccessor.customFieldManager
def optionManager = ComponentAccessor.optionsManager
def ipNameCustomField = customFieldManager.getCustomFieldObject(ipName.fieldId)

def availableConfig = ipNameCustomField.getRelevantConfig(issueContext)
def ipNameOptions = optionManager.getOptions(availableConfig)

def availableOptions = [] as ArrayList<String>

if (appNameValue == 'BRI') {
availableOptions = ['BRI1', 'BRI2']
} else if (appNameValue == 'CA') {
availableOptions = ['CA1', 'CA2']
} else if (appNameValue == 'DM') {
availableOptions = ['DM1', 'DM2']
}

def availableOptionsMap = ipNameOptions?.findAll {
it.value in availableOptions
}

ipName.setFieldOptions(availableOptionsMap)

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Behaviour configuration:-

behaviour_config-1.png

I also include a couple of test screenshots for your reference:-

1. If I am to select the BRI option from the App Name list, the options in the IP Name list are filtered accordingly to BR1 and BR2.

test1.png

2. Similarly, if I am to select the CA option from the App Name list, the options in the IP Name list are filtered accordingly to CA1 and CA2.

test2.png

3. Finally, if I am to select the DM option from the App Name list, the options in the IP Name list are filtered accordingly to DM1 and DM2.

test3.png

Note: The None option cannot be removed. Even if the options from the IP Name list are filtered, the None option will still be displayed. This is an expected Behaviour.

I hope this helps to answer your question. :-)

Thank you and Kind regards,
Ram

Joel Batac December 23, 2022

Thanks Ram.  I know this way, what I was asking  was if i preset the value of App Name in the form (hidden from users and not selecting from drop down) 

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 26, 2022

Hi @Joel Batac,

In your last comment, you mentioned:-

 I know this way, what I was asking  was if i preset the value of App Name in the form (hidden from users and not selecting from drop down) 

Could you please clarify exactly when do you want the preset value for the App Name field to be set and on what condition you want to control the option set for the App Name field? Is it based on the Issue Type?

I am looking forward to your clarification.

Thank you and Kind regards,
Ram

Joel Batac January 3, 2023

Capture.PNG

Joel Batac January 3, 2023

So basically in the form, I preset the value of Application to BRIE if the request type is BRIE. I want this preset value as the basis/trigger for behaviour for the IP Name

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events