Script Runner Escalation service

Jamie Cole October 10, 2019

So I am trying to automate the creation of a new tickets based on the end date of a resolved ticket using the Escalation service in script runner.

The JQL is project = vc AND issuetype = Story AND "Due Date" = -199d

The new issue is being created and linked to the resolved issue so all good there, however I want to populate a set of custom fields in the new ticket, in the script I'm testing with a field called 'Accessibility' or object "customfield_11008" which is a radio button selection options 'yes' or 'no'. I would like to set this to yes. However cannot get this to work.

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager

//origin issue - result of JQL
def issueManager = ComponentAccessor.getIssueManager()
def issueKey = issue.getKey();
def issueID = issue.getId();
def issueTypeName = issue.getIssueType().name
def issueStatusName = issue.getStatus().getSimpleStatus().getName()
log.setLevel(org.apache.log4j.Level.DEBUG);
log.debug "JC Key = $issueKey"
log.debug "JC TYPE = $issueTypeName"
log.debug "JC STATUS = $issueStatusName"
log.debug "JC ID = $issueID"
log.debug "JC Reporter = $issue.reporter.name"

def issueService = ComponentAccessor.issueService
def projectManager = ComponentAccessor.projectManager
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def IssueLinkManager = ComponentAccessor.getIssueLinkManager()

//target project&issue
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
projectId = projectManager.getProjectObjByKey("EGA").id
summary = issue.summary
issueTypeId = "10001"
reporterId = user.name

}

def validationResult = issueService.validateCreate(user, issueInputParameters)
assert !validationResult.errorCollection.hasAnyErrors()


//new issue created
def issueResult = issueService.create(user, validationResult)
def newIssueID = issueResult.getIssue().getId()
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject("customfield_11008")
def fieldConfig = cf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null)
issue.setCustomFieldValue(cf, option)

log.debug "JC NEWID = $newIssueID"
log.info "Issue created: ${issueResult.issue}"


//link to origin issue
IssueLinkManager.createIssueLink(newIssueID, issueID, (Long)10003, (Long)0L, currentUser)

3 answers

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 15, 2019

How about this one?

// add these to the import statements
import
com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

def oldValue = issue.getCustomFieldValue(cf)
def newValue = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null)
def changeHolder = new DefaultIssueChangeHolder() cf.updateValue(null, issue, new ModifiedValue(oldValue, newValue),changeHolder)

and please add  log.error("debug point n") statements so that we can better analyze how the code ran and what are the results. And please attach the logs.

Jamie Cole October 22, 2019

sorry do not understand debug point n ? 

Jamie Cole October 22, 2019
Since modifiying now get :-
runner.canned.jira.admin.EscalationService/preview [c.o.s.c.jira.admin.EscalationService] Escalation Service (Licence ) failed for issue VC-2871
groovy.lang.MissingPropertyException: No such property: fieldConfig for class: Script75
at Script75.run(Script75.groovy:44)
Jamie Cole November 6, 2019

any further suggestions

0 votes
Ben Poulson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2019

In addition to the line @Tuncay Senturk suggested, could you add this line before the field value is set?

 

issue = issueResult.issue

As far as I can tell, the issue variable is never given a value, so it's just using the value scriptrunner set for it, which would be the original issue, not the new issue. Let me know if this worked!

Jamie Cole October 14, 2019

Tried this and didnt work.

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 10, 2019

Could you please try adding below line after setCustomFieldValue?

issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
Jamie Cole October 11, 2019

Tired that and didnt work, infact it stopped the issue link from working

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 11, 2019

Can you see any error message? Actually it should work, there should be something missing.

Setting issue's custom field value might not work unless you cast it to MutableIssue or without issueManager.updateIssue service.

Jamie Cole October 14, 2019

Not sure what you mean by MutableIssue or wothput issueManager service?

Suggest an answer

Log in or Sign up to answer