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

Why this script doesn`t work in postfunction? Edited

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

1 answer

1 accepted

1 vote
Answer accepted
Payne Community Leader May 26, 2021

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Published in Marketplace Apps & Integrations

☕️ Monday coffee with Jexo: Weekly Atlassian news roundup | 21st June 2021

Hi community 👋, as every Monday we're bringing you a quick update on what happened in the Atlassian ecosystem last week. There were a few interesting events like for example the announcement of th...

56 views 0 6
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