Hide/Set as required a field based on the Issue type

Iryna Pazharytskaya June 7, 2024

Dear community,

 

I am trying to configer a behavior in the way that "Additional Information" field is hidden if the issue type is not "Serives Incomplete" and set "Additional Information" field  as required if issue type is "Serives Incomplete".

The issue type is present in a transition pop-up together with the Additional information field but it doesn't seem to work. My code in behaviors is as follows:

IssueFieldBeh.png

def Field1 = getFieldByName("Additional Information")
def NumberField = getFieldById(getFieldChanged())

def selectedOption = NumberField.getValue() as String
def Option1 = selectedOption == "Services Incomplete"

Field1.setHidden(! Option1)
Field1.setRequired (Option1)
Could you please advise?
Best,
Iryna

2 answers

0 votes
Iryna Pazharytskaya June 12, 2024

But if I change it to :

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def sampleTextField = getFieldByName('Additional Information')
sampleTextField.hidden = false
sampleTextField.required = true

if(issueContext.issueType.name in ['Services Incomplete']) {
    sampleTextField.hidden = false
    sampleTextField.required = true
}
the Additional Information field is always reuired (see the AIrequired screenshot)
0 votes
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.
June 11, 2024

Hi @Iryna Pazharytskaya

The approach you are trying will not work as expected.

Since you want to make the change based on the issue type, you must use the Behaviour Initialiser instead of the Server-Side Behaviour.

Below is a sample working code for your reference:-

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def sampleTextField = getFieldByName('Sample Text Field')
sampleTextField.hidden = true
sampleTextField.required = false

if(issueContext.issueType.name in ['Bug', 'Story']) {
sampleTextField.hidden = false
sampleTextField.required = true
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

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

Thank you and Kind regards,
Ram

Iryna Pazharytskaya June 12, 2024

 

Hi Ram,

 

Thank you for your reply. 

If I set it to :

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def sampleTextField = getFieldByName('Additional Information')
sampleTextField.hidden = false
sampleTextField.required = true

if(issueContext.issueType.name in ['Services Incomplete']) {
    sampleTextField.hidden = false
    sampleTextField.required = true
}
the Additional Information field is always reuired (see the AIrequired screenshotAIrequired.png

 

 

But when i set it to:
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

 

@BaseScript FieldBehaviours behaviours
def sampleTextField = getFieldByName('Additional Information')
sampleTextField.hidden = true
sampleTextField.required = false

 

if(issueContext.issueType.name in ['Services'. 'Supplies']) {
    sampleTextField.hidden = true
    sampleTextField.required = false
}
the Additional Information field is always hidden (see the AIhidden screenshot

AIhidden.png

 

Looks like it only looks into the line with 'True' in it and doesn't check what type of issue it is (there are 3 possible Issue types: 

Supplies, 

Services

Services Incomplete

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.
June 12, 2024

Hi @Iryna Pazharytskaya

There appears to be an error in your code.

If you look at this line:-

if(issueContext.issueType.name in ['Services'. 'Supplies']) {
    sampleTextField.hidden = true
    sampleTextField.required = false
}

You should not use a dot to separate the options. Also, there is no point in setting the hidden to true and required to false since it is already set to that by default

Instead, you must use a comma like this:-

if(!(issueContext.issueType.name in ['Services', 'Supplies'])) {
sampleTextField.hidden = false
sampleTextField.required = true
}

Please make the correction and try to test it again.

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

Iryna Pazharytskaya June 12, 2024

Hi Ram,

 

Sorry, it was a typo.

With comma - same result.

 

Thank you

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.
June 12, 2024

Hi @Iryna Pazharytskaya

I'm not sure why it's not working in your environment, because it's working just fine on mine.

Please replace your code with just the logging parameter below and see what is returned when you select the particular issue type. 

log.warn "===============>>>>> Issue Type: ${issueContext.issueType.name}"

Thank you and Kind regards,
Ram

 

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.
June 17, 2024

Hi @Iryna Pazharytskaya

Any update on the log output?

Thank you and Kind regards,
Ram

Iryna Pazharytskaya June 21, 2024

Hi Ram,

 

It still doesn't work

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.
June 23, 2024

Hi Irya,

Please share the log output so I can see what is happening.

Thank you and Kind regards,
Ram

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events