We are using ScriptRunner.
We are changing a priority field in Custom Listener when an event `Issue updated` is happened.
This code updates a `priority` field of issue if user has permission "Assign issues" in Issue Permissions tab of my project.
However, if user does not have permission "Assign issues" in Issue Permissions tab of my project, then this code is not updating priority field.
What can I do to update priority field if user does not have a permission "Assign issues", but user has a permission to "Edit Issues"?
In my view, it should be enough to have a permission "Edit Issues" to be eligible to edit priority field. Is it correct?
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParametersImpl
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
def issue = event.issue
def idPriorityLoIssue = issue.getPriorityObject().getId().toString();
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sequenceField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Послед."}
log.info(sequenceField)
def sequenceFieldValue = issue.getCustomFieldValue(sequenceField)
log.info(sequenceFieldValue)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getOutwardLinks(issue.id).each{ issueLink ->
def linkedIssue = issueLink.getDestinationObject()
log.warn('1. ***** LinkedIssue: *****' + linkedIssue)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
log.warn('1.0. User is' + user)
def issueInputParameters = new IssueInputParametersImpl()
def issueService = ComponentAccessor.getIssueService()
issueInputParameters.setPriorityId(idPriorityLoIssue.toString())
issueInputParameters.setSkipScreenCheck(true)
def validationResult = issueService.validateUpdate(user, linkedIssue.id, issueInputParameters)
log.warn('validationResult.isValid() ' + validationResult.isValid())
if (validationResult.isValid()) {
log.warn('vaild')
issueService.update(user, validationResult)
log.warn('2. ***** Priority of issue is set to: *****' + idPriorityLoIssue)
def seqFieldLinkedIssue = customFieldManager.getCustomFieldObjects(linkedIssue).find {it.name == "Послед."}
if(seqFieldLinkedIssue){
def changeHolder = new DefaultIssueChangeHolder()
seqFieldLinkedIssue.updateValue(null, linkedIssue, new ModifiedValue(linkedIssue.getCustomFieldValue(seqFieldLinkedIssue), sequenceFieldValue),changeHolder)
}
} else {
log.info('not vaild')
log.warn validationResult.errorCollection.errors
log.info('3. ***** Priority of issue is NOT set to: *****' + idPriorityLoIssue)
}
}
The issue is in your last 2 lines.
selectedValue is specific to the parent issue, attempting to check this for a null value in the every{} block is not achieving what you think.
Here is the complete logic that you are trying to accomplish if I understand correctly
issue.subTaskObjects.every{subTaskIssue->
def UOTypeValue = subTaskIssue.getCustomerFieldValue(cf)
UOTypeValue != null
}And it can be further simplified because of the built-in groovy truthiness
issue.subTaskObjects.every{it.getCustomerFieldValue(cf)}
Hello @PD Sheehan , thanks for the corrections and your quick response.
This helps me a lot! :)
Have a nice day.
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.