Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

ScriptRunner post-function: error when trying to set custom field value Edited

Hi there!

I'm trying to get an active sprint name from a given board in the post-function and write a sprint name to a custom field. 

Here is the script that I use in the post-function:

import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager


/**
* Configurable section
*/
// Enter the name of the board to which you want to add the issue to the first active sprint
def rapidBoardId = 619
def cfm = ComponentAccessor.getCustomFieldManager()
def item = cfm.getCustomFieldObjectByName("Item")
def active

log.error("item: " + item)
@WithPlugin("com.pyxis.greenhopper.jira")

@JiraAgileBean
RapidViewService rapidViewService

@JiraAgileBean
SprintIssueService sprintIssueService

@JiraAgileBean
SprintManager sprintManager

Issue issue = ComponentAccessor.getIssueManager().getIssueObject("your issue key")

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def view = rapidViewService.getRapidView(loggedInUser, rapidBoardId).getValue()

if (! view) {
log.warn("No view with this ID found")
return
}

def sprints = sprintManager.getSprintsForView(view).getValue()
def activeSprint = sprints.find { it.active }
log.debug activeSprint

if (activeSprint) {
active = activeSprint.name
issue.setCustomFieldValue(item, active)
}
else {
log.info ("No active sprints were found for board: ${view.name}")
}

As a result of post-function I get an error:

2018-12-12 04:19:57,388 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SM-964, actionId: 61, file: <inline script>
java.lang.NullPointerException: Cannot invoke method setCustomFieldValue() on null object
	at Script126.run(Script126.groovy:51)

 

Please help me to understand what is wrong in the script ans how to make it work. 

Thank you! 

1 answer

1 accepted

1 vote
Answer accepted

Hi Elena!

It seems that you call this into Script console. 

Variable issue is defined as current issue when code is used into postfunction.

You need to use correct issue key here

Issue issue = ComponentAccessor.getIssueManager().getIssueObject("your issue key")

 You also need to save your changes into DB when use script console with IssueManager.updateIssue() method. https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/IssueManager.html#updateIssue-com.atlassian.jira.user.ApplicationUser-com.atlassian.jira.issue.MutableIssue-com.atlassian.jira.issue.UpdateIssueRequest- 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

52 views 0 2
Read article

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