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

Update priority field if user does not have a permission "Assign issues"

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)
}
}

1 answer

1 accepted

0 votes
Answer accepted

I suggest using IssueManager to update issues instead of IssueService. 

Like so:

import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor

issue.setPriority(priority)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

@Ivan Tovbin Thanks for your answer. I've tried to use your code, but the following code is outlined by red color:

 

issue.setPriority(priority)
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

The error says:

1. Cannot find matching method "setPriority"

2. Cannot find matching method "updateIssue"

Can you show me the code as it looks like on your end?

So the final code should look like this:

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Logger
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.util.ImportUtils
import org.apache.log4j.Category
import java.sql.Timestamp
import com.atlassian.jira.event.type.EventDispatchOption;

def log = Logger.getLogger("com.acme.CreateSubtask")
IssueManager issueManager = ComponentAccessor.getIssueManager()

def issue = issueManager.getIssueObject("Bar-1")

def customFieldManager = ComponentAccessor.getCustomFieldManager()


def environmentValue = issue.getEnvironment();
log.info('environmentValue ' + environmentValue)
issue.setEnvironment('New Environment 1')


def user = ComponentAccessor.getJiraAuthenticationContext()
.getLoggedInUser()
log.info('user ' + user)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH
, false)

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

304 views 9 7
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