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

Post function script to update linked items Edited

I have written a scriptrunner post function that should update the status of a linked item when its run. Essentially, when our dev team reviews and accepts a client issue for development we want to clear the assignee (with conditions) and reviewed flags on the client issue. This script i have generates no sytax errors and runs without issue but doesnt seem to want to update the linked item: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink

def issueService = ComponentAccessor.getIssueService()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def v3Reporter = issue.getReporter()
def linkType = ["Inducted"]
def linkMgr = ComponentAccessor.getIssueLinkManager()
def desc = "start"

for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
if (linkType.contains(link.issueLinkType.name)) {
MutableIssue clientIssue = link.sourceObject as MutableIssue

def customFieldManager = ComponentAccessor.customFieldManager
def clientAssignee = clientIssue.getAssignee()
def review = customFieldManager.getCustomFieldObjectByName("Reviewed by Product Team")
def reviewValue = clientIssue.getCustomFieldValue(review)
if (v3Reporter == clientAssignee){
clientIssue.setAssignee(null)
clientIssue.setCustomFieldValue(review, "Yes")
} else {
clientIssue.setCustomFieldValue(review, "Yes")
}
}
}

1 answer

ok - so i now realize that i need to use the issue service to make the updates and have re-written to this but the update doesnt seem to be valid: 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.link.IssueLink

IssueService issueService = ComponentAccessor.getComponent(IssueService);
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager);
def optionsManager = ComponentAccessor.getComponent(OptionsManager);
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def v3Reporter = issue.getReporter()
def linkType = ["Inducted"]
def linkMgr = ComponentAccessor.getIssueLinkManager()
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {
if (linkType.contains(link.issueLinkType.name)) {
def clientIssue = link.sourceObject
def clientAssignee = clientIssue.getAssignee()
def review = customFieldManager.getCustomFieldObjectByName("Reviewed by Product Team")

if (v3Reporter == clientAssignee){
issueInputParameters.setAssigneeId(null)
issueInputParameters.addCustomFieldValue(review.id, "Yes")
} else {
issueInputParameters.addCustomFieldValue(review.id, "Yes")
}
def update = issueService.validateUpdate(user, clientIssue.id, issueInputParameters)
if (update.isValid()) {
issueService.update(user, update)

}
}

 

any thoughts on what i'm missing? 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

240 views 2 5
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