Forums

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

get value from selected customfield

Olivera Tancheva
January 16, 2019

I am trying to compare a value from a multiselect customfield. i did the following code:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.scriptrunner.runner.util.UserMessageUtil

def issueManager = ComponentAccessor.getIssueManager();
def userManager = ComponentAccessor.getUserManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cField = customFieldManager.getCustomFieldObject("customfield_12032");
def cFieldValue = issue.getCustomFieldValue(cField);

if (cFieldValue.toString() == "Business Trips")
{
    UserMessageUtil.error('Please select project.')
}

 

But the code only works when I put cFieldValue.toString() == "None". I can't seem to figure out why it doesn't work for the other options.

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Nic Brough -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 Champions.
January 9, 2022

I have to question why you don't want to use permissions for this, and also why you think there is any point in it.  What is the benefit of removing an option from a menu, one that you still want people to be able to do, and now have to cast around with fiddly url building to be able to do it?  

What do you gain from making things harder for people to find?

1 vote
Vikrant Yadav
Community Champion
January 9, 2022

Hi @Garden16_  For this you have to use Script Fragment feature of Script runner. In Script Fragment use "Hide System or Plugin UI element". 

Fragment Hide.PNG

In Hide What section, select clone-issue,move-issue and subtask-to-issue (if you want to stop conversion)

Configuration.PNG

 

In Condition Block , enter the condition based on your requirement , include subtask issue type as well you want to hide Convert to Issue button from More.

import com.atlassian.jira.component.ComponentAccessor

if(jiraHelper.project?.key == "VY" && issue.issueType.name == "Bug" ) {
false
} else {
true
}

 Hope it Works for you!

Thanks,

V.Y

TAGS
AUG Leaders

Atlassian Community Events