Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,856
Community Members
 
Community Events
184
Community Groups

Is it possible to set flag to an issue using Scriptrunner post function

Hi,

Is it possible to set flag = true on post function using scrip runner?

1 answer

0 votes
Hristo Hristov
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Apr 24, 2023

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events