Need to show a scripted field based on priority selection.

Akshay Sawan November 13, 2019

I am using the following code to show a custom scripted field based on the priority I select. This is a JIRA service desk project, where if the customer selects "P1- Critical" as the priority, it should show the scripted field "Reason for Critical Priority" which is a long text field.

Please note that this field needs to be shown in the Customer Request Screen that is configured using the JIRA service desk admin panel where we can create request types.

In the Edit Request Type, screen where you can add the fields required, it is not showing up in the Add a Field popup even though I had added it to the screen View Screen tab in the JIRA admin section.  Please refer to the images attached for the same. (I have hidden a few fields due to privacy policies)image.png

image.png

PFB the code below.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.*

@BaseScript FieldBehaviours fieldBehaviours
def ff = getFieldById(COMPONENTS)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

def issue = issue as Issue
def cFieldValue = issue.getPriority().getName()

def priorityReason = customFieldManager.getCustomFieldObjectByName("Reason for Critical Priority")

/*if(cFieldValue.equals("P4 - Minor")){
priorityReason.setRequired(true)
}*/

// Get the current user
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get the changed field
def exampleField = getFieldById("customfield_13116")

if (cFieldValue.equals("P1- Critical")) {
exampleField.setHidden(false)
} else {
exampleField.setHidden(true)
}

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 15, 2019

You might have a fundamental misunderstanding of what a Scripted Field is. (Or I completely misunderstood what you are trying to explain).

Scripted Fields are always read-only (and as such never available on edit edit or created screen). They are calculated on the fly for every request to view the issue based on the script you provide.

What I think you need is a regular multi-line text field.

Then, you would use a Behaviour configuration with the script you shared (I think that came from a behaviour) to show or hide the text field based on the criticality value.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events