Hi,
I have a script working perfectly when I call it from my workflow.
But, I also want to use the same script from a scheduler (Systems->Services).
Could someone correct the script? please
Thanks
import org.apache.log4j.Category import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.search.SearchException import com.atlassian.jira.web.bean.PagerFilter import com.atlassian.jira.issue.util.IssueChangeHolder import com.atlassian.jira.issue.util.DefaultIssueChangeHolder; import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.issue.*; import java.sql.Timestamp def jqlSearch = "project = 'AISC - Suivi des demandes' and ('Date de livraison' >= startOfMonth() and 'Date de livraison' <=now()) and status = Validation" //If you are going to use a JIRA version => 7 then you should get the ApplicationUser instead of User, to do that remove the .directoryUser def user = ComponentAccessor.getJiraAuthenticationContext().getUser().directoryUser def searchService = ComponentAccessor.getComponentOfType(SearchService.class) SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch) def value = 0 def customFieldManager = ComponentAccessor.getCustomFieldManager() def myCustomField = customFieldManager.getCustomFieldObjectByName("Temps d'intervention") if (parseResult.isValid()) { try { def results = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()) def issues = results.getIssues() issues.each { if (it.getCustomFieldValue(myCustomField)) value += it.getCustomFieldValue(myCustomField).toInteger() } } catch (SearchException e) { e.printStackTrace() } } else { log.warn("Invalid query") return null } IssueChangeHolder changeHolder = new DefaultIssueChangeHolder(); //ComoponentManager = gestionnaire de composant JIRA ComponentManager componentManager = ComponentManager.getInstance() //CustomFieldManager = gestionnaire de customfield JIRA CustomFieldManager cfManager = componentManager.getCustomFieldManager() // Le champ "Total intervention M0" CustomField cfTotalInterMCourant = cfManager.getCustomFieldObject("customfield_11405") // Update the value cfTotalInterMCourant.updateValue(null, issue, new ModifiedValue("", value.toString() ), changeHolder);
ok, that's what I like to hear. Thanks for letting us know then.
@Jamie Echlin [Adaptavist]
Nothing to do. I wanted to inform you that my script is working.
You have nothing to do.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the question? Or would you prefer me just to go through all that code, work out what you want it to do, then work out why it's not doing that, rewrite it, and post it back here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie Echlin [Adaptavist]
import org.apache.log4j.Category
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.*;
import java.sql.Timestamp
Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
int currentDay = localCalendar.get(Calendar.DATE);
println currentDay
if ( currentDay == 18 ){
println "WE ARE IN CURRENT DAY _script Somme Precedent"
def jqlSearch = "project = 'AISC - Suivi des demandes' and status was in (Validation) and ('Date de livraison' >= startOfMonth(-1) and 'Date de livraison' <=endOfMonth(-1))"
def userManager = ComponentAccessor.getUserManager()
def issueManager = ComponentAccessor.getIssueManager()
def searchService = ComponentAccessor.getComponentOfType(SearchService)
def user = userManager.getUserByName("yk3520").directoryUser
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
def value = 0
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def myCustomField = customFieldManager.getCustomFieldObjectByName("Temps d'intervention")
if (parseResult.isValid()) {
try {
def results = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = results.getIssues()
issues.each {
if (it.getCustomFieldValue(myCustomField))
value += it.getCustomFieldValue(myCustomField).toInteger()
}
} catch (SearchException e) {
e.printStackTrace()
}
} else {
log.warn("Invalid query")
return null
}
// Save the value at custom field with name A number custom field of issue with key TEST-1
def targetIssue = issueManager.getIssueByCurrentKey("SL-8")
def customField = customFieldManager.getCustomFieldObjects(targetIssue).find {it.name == "Total intervention M-1"}
if (customField) {
def changeHolder = new DefaultIssueChangeHolder()
customField.updateValue(null, targetIssue,
new ModifiedValue(targetIssue.getCustomFieldValue(customField), value.toString()),changeHolder)
log.debug "Custom field $customField.name} updated with value ${value}"
return
}
log.warn "Custom field ${customField?.name} was not updated"
}
else
{
println "WE ARE NOT IN CURRENT DAY"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie Echlin [Adaptavist]
It's not exactly the same.
We can't execute the same groovy script called from a wf in a scheduler.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
duplicate of https://answers.atlassian.com/questions/38385348 which already has answers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.