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)
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please try adding below line after setCustomFieldValue?
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tired that and didnt work, infact it stopped the issue link from working
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure what you mean by MutableIssue or wothput issueManager service?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.