Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Copy customfield value from var to var.

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 Dec 20, 2021

Hello @Fabian Laqua ,

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

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you