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,560,502
Community Members
 
Community Events
185
Community Groups

workflow validator - java.lang.NullPointerException error

Edited

Hello,

I would like to make a validator with simple scripted validator.

Parent Feature is the key of linked issue.

Internal Feature is a custom field, type Checkbox , It has one option- 'Yes'. 

I have an error- java.lang.NullPointerException,  and the code all the time return false.. What is the problem with my code ?

Thanks.

 

 

The code is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager

//get the parent feature issue

Issue featureT = ComponentAccessor.issueManager.getIssueObject('Parent Feature');

//custom field internal feature
def internal = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Internal Feature");
def selectedValues = internal.getValue(featureT);
def bool=true;
if(selectedValues!=null)
{
bool=true;
}
else
{
if(featureIssue.fixVersions != issue.fixVersions)
{
bool=false;
}
}
return bool;

2 answers

1 vote
Dar Kronenblum
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.
Aug 05, 2018

Hi Daniel,

Is it the whole script?

not sure what the value 'Parent Feature' in the following line represent, the getIssueObject function should get an issue key (e.g. TEST-54)

Issue featureT = ComponentAccessor.issueManager.getIssueObject('Parent Feature');

Dar

Hi Dar,

Is, it is a whole script..

'Parent Feature' is the key of the linked issue.

0 votes
Neta Elyakim
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.
Aug 08, 2018

Hey @Dan27

As I can see from your script, you have a few problems-

1) You store some string when you get the Feature issue object- if you meat that the string "Parent Feature" is a field that contains the Feature key- you can see it in the script I added (if you don't need it like that and you have some absolute issue key, you can add it hardcoded in the script)

2) You are not consistent with the variables (where does "featureIssue" come from?)

3) When you take value from a custom field (selectedValues) first you need to take the issue object, value, and custom field, like this- issue.getCustomFieldValue(cf)

Try this:

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

def customFieldManager = ComponentAccessor.getCustomFieldManager();
//get the parent feature issue
String parentFeatureKey = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Parent Feature"));
Issue featureIssue = ComponentAccessor.issueManager.getIssueObject(parentFeatureKey);
//custom field internal feature
def internal = customFieldManager.getCustomFieldObjectByName("Internal Feature");
def selectedValues = featureIssue.getCustomFieldValue(internal);

def bool=true;
if(selectedValues!=null){
bool=true;
}else{
if(featureIssue.fixVersions != issue.fixVersions){
bool=false;
}
}
return bool   

Hope this information will help you in the future. 

Let me know if it's work for you

 

Neta

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events