Hi! Try to use this one example
https://matejholy.github.io/jira-programming/processing-issues-from-a-jql-search/
Works fine only in script console. But when i trying to use it in postfunction - nothing happened.
Jira Server 8.5 + scriptrunner
error log
2021-05-25 18:52:20,284 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue CIW-613 for user 'stekolnikov'. View here: https://XXXXXXXXXXXX/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=CIW%3A+Project+Management+Workflow&descriptorTab=postfunctions&workflowTransition=91&highlight=5 groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script3863 at Script3863.run(Script3863.groovy:17)
my code:
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.user.ApplicationUser
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.issue.search.SearchResults
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
// set up logging
def log = Logger.getLogger("com.example.jira.script.ProcessJQL");
def Grade = customFieldManager.getCustomFieldObject("customfield_14209")
log.setLevel(Level.INFO);
// define JQL query
String jqlSearch = "project = INFO AND issueType = Task AND Employee = akim";
// required objects
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
IssueManager issueManager = ComponentAccessor.getIssueManager();
// validate the query
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch);
if (parseResult.isValid()) {
// do the search
SearchResults searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
for (Issue issue : searchResult.getResults()) {
log.info("Found issue: " + issue.getKey());
// to update issue convert it to MutableIssue
MutableIssue mutableIssue = issueManager.getIssueObject(issue.getId());
mutableIssue.setSummary(issue.getSummary() + " UPDATED");
//mutableIssue.setCustomFieldValue(Grade, "Jun 2")
issueManager.updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false); // false = do not send e-mail notifications
}
} else
log.error("Invalid JQL: " + jqlSearch);
UPD: Solve problem by using
def Grade = ComponentAccessor.customFieldManager.customFieldObjects.findByName("Grade")
instead
def Grade = customFieldManager.getCustomFieldObject("customfield_14209")
I see your update; yes, that's one way, or alternatively define customFieldManager toward the top of your script and then use it wherever needed, i.e.
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.