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

Copy customfield value from var to var.

Fabian
Contributor
December 10, 2021

I hope you can help me. Maybe i misunderstood something.

I want to set a variable from type customfield with a determined customfield object. If i use getCustomFieldObject, everything works fine. But if i use getCustomFieldObjectByName or getCustomFieldObjectsByName, an error occures:

Script console script failed: 
java.lang.NullPointerException
	at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:951)
	at com.atlassian.jira.issue.Issue$getCustomFieldValue$1.call(Unknown Source)
	at Script1142.addFieldValuesToOutput(Script1142.groovy:147)
	at Script1142.run(Script1142.groovy:128)

 And i dont understand, what the problem is in my script:

String sinput = "Serial Number, Assigned Group, customfield_10234"
String[] fields = sinput.split(",")

fields.each {
try {
CustomField cField = null
if (it.trim().contains("customfield")) {
cField = cfm.getCustomFieldObject(it.trim()) // If input is customfield_id
} else {
Collection<CustomField> ccf = cfm.getCustomFieldObjectsByName(it.trim()) // If input is custom field name
log.warn("CustomField: " + (ccf.getAt(0) instanceof CustomField)) // true - it is a customfield
MutableIssue issue = issueManager.getIssueObject("CSR-9588") // Test with a issue
log.warn(cfm.getCustomFieldObjectByName(it.trim())) // Works
log.warn(issue.getCustomFieldValue(cfm.getCustomFieldObjectByName(it.trim()))) // Works
cField = ccf[0] // error
// if (!ccf.empty) cField = ccf.getAt(0)
}
//...
} catch(Exception e) {
// ...
}
}

 

I hope you can help me.

Kind regards

 

1 answer

0 votes
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 20, 2021

Hello @Fabian ,

I tried your script and it is working properly, ccf[0] will return an "ImmutableCustomField". Are you sure you are using correct custom field names ?

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.

Learn more
AUG Leaders

Upcoming Jira Events