Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Hide Priority value/options based on IssueType on Customer Portal

Alvin
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.
September 23, 2018

Hi Community, is it possible to hide certain values/options in Priority Field (System Field) on Customer Portal based on Issue Type (Incident)

I am using this code in Behavior using Scriptrunner, and I know I might doing it wrong, can you help me out of it? Thanks!

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*

// Get the current issue type from the issue context incase the issue
// has not been created yet
def issuetype = underlyingIssue?.getIssueType().name

// Get a pointer to my select field
def selectcf = getFieldByName("Priority")

// Get pointers to the required custom field and otion managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(selectcf.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

// If issue type matches change the cf values to be displayed
if (issuetype.contains("Incident")) {
def optionsMap = options.findAll {
it.value in ["A", "B"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}

1 answer

0 votes
Daniel Yelamos [Adaptavist]
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.
September 24, 2018

Hi Alvin

Check this bit of code out. This would get all of the priorities with less than "2". Priorities are ordered by id.

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY


def constantsManager = ComponentAccessor.getConstantsManager()
def allowedPriorities = constantsManager.getPriorityObjects().findAll {
it.id.toInteger() < 2
}.collectEntries {
[(it.id): it.name]
}
getFieldById(PRIORITY).setFieldOptions(allowedPriorities)

 Do say if I can help you further.

Cheers

DY

Alvin
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.
September 24, 2018

Hi @Daniel Yelamos [Adaptavist] , Thank you for a very quick turn-around. I've already made a new question, Kindly check it via this link if you have time. Thanks

https://community.atlassian.com/t5/Jira-questions/Custom-Added-Priority-doesn-t-return-correct-order-using/qaq-p/899202#M288352

Suggest an answer

Log in or Sign up to answer