Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set a condition on an insight post function

Juhaina Almama
Contributor
October 22, 2021

Hi

I am using the insight post function" Set the value of an object attribute with a predefined value" to update the insight attribute "Status" with the value "Running" if no other issues are open for the same service:

I can get the issues from this query:

 

"project = INC AND issuetype = Incident and status not in (Completed,Canceled,Closed)"

I am tring to write the grivyscript below, can any one help me to check if there any issue which have the same service so the post function will not update the attribute : 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.search.SearchQuery

// The JQL query to search with
final jqlSearch = "project = INC AND issuetype = Incident and status not in (Completed,Canceled,Closed)"
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchResults = searchProvider.search(SearchQuery.create(jqlSearch, user), PagerFilter.unlimitedFilter)
/// The name of the custom field to alter
final Service = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12345)

def value = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12345)); // Change ID to the correct one

/* If an insight custom field has an object called the same issue service it will fail */
if {
return false;
}

1 answer

1 vote
Tessa Tuteleers
Community Champion
October 22, 2021

Hi @Juhaina Almama ,

to run a JQL query with groovy and return the list of issues, you can use the SearchService together with the JqlQueryParser, PagerFilter and UserManager.

instead of "searchProvider.search", try jqlParser.parseQuery and searchService.search(...

Hope this helps, if you are still stuck, let me know!

  • Tessa
Juhaina Almama
Contributor
October 24, 2021

Hi Tessa 

Thanks for answering.

I am just a beginner in this kind of script, can you help me more ? such as rewriting the entire script. 

how is it to check all the issues that come from the query?

Regads Juhaina

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events