Getting Custom Field Value in ScriptRunner Scripted Field

I'm trying to get the value of a Script Field in another Script Field using the code below, but for some reason the script is failing as can be noted by the second log.info not being called.

Is there an alternative way of getting the value?

 

def issueLinkManager = ComponentAccessor.getIssueLinkManager();
def cfManager = ComponentAccessor.getCustomFieldManager();
def cfTeam = cfManager.getCustomFieldObject("customfield_13205");
def cfTheme = cfManager.getCustomFieldObject("customfield_13203");

for (IssueLink issueLink : issueLinkManager.getInwardLinks(issue.getId())) {
if (issueLink.getIssueLinkType().getId() == 10702) {
log.info('before');
def theme = issue.getCustomFieldValue(cfTheme);
log.info('after');
return theme;
}
}

 

 

1 answer

Hey Ron!

Without looking at your logs, all I can guess is that cfTheme is returning null for whatever reason, causing an exception to be thrown. Looking into your atlassian-jira.log file may provide you with some insight here.

However, the only way that this would be a problem is if either the cf didn't exist, or you accidentally typed in the id wrong. Assuming the latter, try using this method to get the custom field object instead:

def cfm = ComponentAccessor.customFieldManager
cfm.getCustomFieldObjectByName("Name of CF")//Input: Name of the Custom Field

Try that out and see if you still have the same problem.

If the issue persists, try to log out the contents of the custom field to see if it's returning what you expect it to.

Let me know what you find! :)

Aidan 

Hi Aidan,

The value of cfTheme is not null as I'm able to output the field name and description via a log call.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

827 views 2 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you