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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,959
Community Members
 
Community Events
185
Community Groups

Help with script runner - required field

Hi, I need a little help to build a script that does the following:

For a specific issue type, a custom field is required when this issue is closed.

Some background:

  • The project has several issue types
  • When the issue type "Service Desk" is being Closed (transition) the script must validate if custom field is not empty (it's a Select List (single choice) type).

I'm new at JIRA and I'm not a developer, so any help is highly appreciated :)

I looked at this behaviour example and I think this will do the trick, however set to issue type instead of Resolution....any clue where I should start?

import com.atlassian.jira.issue.resolution.Resolution 

def resolutionField = getFieldById("resolution")

def fixVersionsField = getFieldById("fixVersions")

def resolution = resolutionField.getValue() as Resolution

if (resolution.name == "Fixed") {

fixVersionsField.setRequired(true)

fixVersionsField.setHidden(false)

}

else {

fixVersionsField.setRequired(false)

fixVersionsField.setHidden(true)

} 

 

1 answer

0 votes
Laurent Bierge
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.
Sep 29, 2017

Hi, 

If i were you, i would try to do this along with the workflow.

You can choose the transition you want, the one that close the issue, and add a validator.

The validator don't disable the permission of transition but cancel it when the condition are not met.

So, go to your workflow, transition, validator and add one.

Choose script validator, it's powered by scriptrunner.

And you may try something like this;

import com.atlassian.jira.component.ComponentAccessor

def cfManager = ComponentAccessor.customFieldManager
def cf = cfManager.getCustomFieldObject((Long) 16000) //your custom field with its Id as a parameter, 16000 is an exemple

if (issue.issueType.name == "Service Desk"){
if (issue.getCustomFieldValue(cf) == null) {
return false
} else {
return true
}
} else {
return true
}

You'll need the id of your customField. You can find id when you try to configure it on the UI. It should be somewhere on the page or in the link above.

 

If you're new to Jira and want to get along with scriptrunner, i recommand that you look into the ComponentAccessor interface.

Regards,

 

Laurent

Laurent Bierge
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.
Oct 02, 2017 • edited
if (issue.issueType.name == "Service Desk"){
if (issue.getCustomFieldValue(cf) != null) {
return true
} else {
return false
}
}

You can replace the end of the script with this, it's a bit cleaner.

(i'm not a dev either)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events