You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
Is it possible to set flag = true on post function using scrip runner?
Hello Hadas,
Yes, it is possible, let me give you what I have done for my use case, maybe it will help you out for yours:
- First here is a brief description of the logic. I want all my tickets, which are returned based on JQL query to be flagged, if they have links that are of type "Blocked-by" (basically if my ticket is blocked by other ticket I will flag it). I am using Jira Datacenter version 9.4. Cheers.
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import groovy.transform.Field
@Field String customFieldName = 'Documentation update required' // Correct name of the flagging field, checkbox
@Field String customFieldValue = '.' // value for flagging checkbox
def List<Option> getOptions(Issue issue, CustomField customField, List<String> optionList) {
def config = customField.getRelevantConfig(issue)
def options = ComponentAccessor.getOptionsManager().getOptions(config)
def optionsToSelect = options.findAll { it.value in optionList }
return optionsToSelect
}
// flag desired issues
def void updateIssues(MutableIssue issue, ApplicationUser user, String linkedIssueStatus, String type) {
if(type.equals("Blocker") && !linkedIssueStatus.equals("Closed") && !linkedIssueStatus.equals("Resolved")){
log.info("Updating..." + issue.getKey())
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(issue).findByName(customFieldName)
assert customField : "Could not find custom field with name $customFieldName"
issue.setCustomFieldValue(customField, getOptions(issue, customField, ["."]))
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// edit this query to suit your needs
def query = jqlQueryParser.parseQuery("myquery...")
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
search.results.each { documentIssue ->
// if you need a mutable issue we can do:
def issue = issueManager.getIssueObject(documentIssue.id) // root issue
//List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
// Linked issues here are blocked by ... X issue
for (Iterator<IssueLink> outIterator = allInIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
String linkedIssueStatus = issueLink.getSourceObject().getStatus().getName(); // dont get destination, because its the root issue
String type = issueLink.getIssueLinkType().getName();
// flag it and update it
updateIssues(issue, user, linkedIssueStatus, type);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.