Customize Priority based on custom field

uday ramakrishna December 28, 2011

Hi,

I have a custom field (date type) that accepts users input to request for a due date for the project. Is there a way to set the Priority label once the ticket has been created to reflect what was chosen by the end user? Ideally i want to use High Priority if that date field was selected when the ticket was created.

8 answers

2 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2011

Hi Uday,

you can use a groovy script for this, you can compare the date type customfield value with the currrent date and based on the difference you can set the priority.

you will need the script runner plugin for this and you will have to place your script as a post function on your create transition.

Below is a script which sets the duedate based on priority, hope you find it useful :)

import java.sql.Timestamp
import com.atlassian.jira.issue.MutableIssue
 
// initializing the priority


def BLOCKER = 1;
def CRITICAL = 2;
def MAJOR = 3;
def MINOR = 9;
def Trivial = 30;
 

// calender which returns the date according to the priority defined

private GregorianCalendar getDate(double roll){
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.set(Calendar.HOUR_OF_DAY,0);
        cal.set(Calendar.MINUTE,0);
        cal.set(Calendar.SECOND,0);
        cal.set(Calendar.MILLISECOND,0);
 
        for (int x=0;x<roll;x++){
                cal.add(Calendar.DAY_OF_MONTH,1);
        }
 
        return cal;
}
 
 

MutableIssue mutableIssue = (MutableIssue) issue;
def priority = mutableIssue.getPriority().getString("name");
def setDueDate = mutableIssue.getDueDate();
 //only set the dueDate if the date isn't already set (i.e. if it == null).

        GregorianCalendar cal;

         if(priority.equals("Critical")){
                cal = getDate(CRITICAL);
        } else if(priority.equals("Major")){
                cal = getDate(MAJOR);
        } else if(priority.equals("Minor")){
                cal = getDate(MINOR);
        }
        Timestamp dueDate = new Timestamp(cal.getTimeInMillis());
        mutableIssue.getPriorityObject();
        mutableIssue.setDueDate(dueDate);

uday ramakrishna December 29, 2011

Hi Mizan,

Much appreciate you support in providing me with the code. Unfortunately it has been ages since i worked on java and much behind this. Let me see how i can use this :).

Also i need the due date to be set after the ticket is created when the developer is seeing the ticket. So i am not sure which page needs to be edited to add your code.

Regards

Uday

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2011

Script runner plugin will make your task easy.

Also i need the due date to be set after the ticket is created when the developer is seeing the ticket. So i am not sure which page needs to be edited to add your code.

You just need to add a script post function on the create transition of ur workflow and give the path of the above groovy script.

uday ramakrishna December 29, 2011

Thansk i will try install Script Runner and see how far it goes. Thanks much for your help.

1 vote
Rumceisz April 9, 2012

Hi Jamie,

I changed the extension to .groovy manually, bit it still doesn't work. I summarize what I have done (maybe it can help for Uday too):

* I saved the script (setduedate.txt above) to a file

* I changed the extension to .groovy (is there a program that convert the extension or can it be changed manually?)

* I uploaded the script to a folder which our JIRA can reach

* I added a Script Post-Function to the Create Issue event

What can be a problem or missing something? The script-runner plugin is enabled in our JIRA but maybe the javascript is banned(?)

Or the script is not correct. Actually I never coded Javascript earlier but I can understand the script. I copied the script that Mizan had posted above and I changed only the priorities names because we use custom names (these are only captions, aren't they?). I guess all the JIRA works the same so the script might be the same for my JIRA too(?).

Thank you for all your trouble in help!

Best regards,

Rumi

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2012

i assume you are using windows , open the script in a notepad , then file>>save as>>enter "filename"(setduedate.groovy)>>Enter "save as type"(all files) .

When you add the script to the postfunction provide the correct path+/setduedate.groovy

let me know what happens :)

Rumceisz April 9, 2012

Hi Mizan,

when I renamed the file to 'setduedate.groovy' and chose Save as type (all files), it was saved as setduedate.txt again. Is it correct?

Rumi

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2012

download this file . i have saved your script in .groovy format. I even doubt your script , the names of your priorities contain spaces not sure whether it is the correct way of naming variable . you can try using id's

Rumceisz April 9, 2012

Thank you!

I set the script but it still doesn't work.

You say that the priority ID can be better to use: you mean the ID what I get when I hover the mouse over the Edit button?

This way? 'def Sev 1 - Critical = 1'-> 'def 6 = 1'

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2012

Welcome :) We feed on karmas you can like my posts ;)

No need to use id's . i have updated the script . try this .

let me know what happens

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2012

Make sure you provide the full path to the file as it is on the server...

Also look in your log file for error messages... doing this without feedback is like trying to play chess without being able to see the pieces.

Rumceisz April 9, 2012

Hi,

thanks for suggesting the log file!

I got the following error message:

2012-04-10 13:57:57,140 TP-Processor8 ERROR u517593 837x342543x1 fmw402 57.56.132.217 /secure/CreateIssueDetails.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script8.groovy: 50: expecting '}', found '' @ line 50, column 42.
ableIssue.setDueDate(dueDate);

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2012

A parenthesis is missing

Add a parenthesis here in the code ,

} else if(priority.equals("Sev 4 - Low")){
                cal = getDate(Sev4);
 }

Rumceisz April 9, 2012

Hi,

it still doesn't work but the error message changed:

2012-04-10 15:12:08,796 TP-Processor19 ERROR u517593 912x347954x1 fmw402 57.56.132.217 /browse/ADMIN-978 [atlassian.plugin.web.DefaultWebInterfaceManager] Could not evaluate condition 'de.oio.agileplan.security.CanUseAgilePlan@3fb199' for descriptor: i-AgilePlan-Jira-plugin:de.oio.agileplan.menuitem (null)
java.lang.reflect.UndeclaredThrowableException
	at $Proxy1210.getUserRights(Unknown Source)
	at de.oio.agileplan.security.AbstractAgilePlanCondition.shouldDisplay(AbstractAgilePlanCondition.java:53)
	at com.atlassian.plugin.web.DefaultWebInterfaceManager.filterFragmentsByCondition(DefaultWebInterfaceManager.java:172)
	at com.atlassian.plugin.web.DefaultWebInterfaceManager.getDisplayableItems(DefaultWebInterfaceManager.java:107)
	at com.atlassian.jira.plugin.webfragment.JiraWebInterfaceManager.getDisplayableItems(JiraWebInterfaceManager.java:68)
	at com.atlassian.jira.plugin.webfragment.DefaultSimpleLinkManager.getLinksForSection(DefaultSimpleLinkManager.java:129)
	at com.atlassian.jira.plugin.webfragment.DefaultSimpleLinkManager.getLinksForSection(DefaultSimpleLinkManager.java:134)
	at sun.reflect.GeneratedMethodAccessor374.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:234)
	at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:203)
	at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)
	at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:327)
	at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:51)
	at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:95)
	at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
	at org.apache.velocity.Template.merge(Template.java:256)
	at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:422)
	at com.atlassian.velocity.DefaultVelocityManager.getEncodedBody(DefaultVelocityManager.java:77)
	at com.atlassian.velocity.DefaultVelocityManager.getEncodedBody(DefaultVelocityManager.java:61)
	at com.atlassian.velocity.DefaultVelocityManager.getEncodedBody(DefaultVelocityManager.java:56)
	at com.atlassian.jira.web.component.AbstractWebComponent.getHtml(AbstractWebComponent.java:33)
	at com.atlassian.jira.web.component.webfragment.WebFragmentWebComponent.getHtml(WebFragmentWebComponent.java:48)
	at sun.reflect.GeneratedMethodAccessor373.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:234)
	at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:203)
	at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)
	at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:220)
	at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
	at org.apache.velocity.Template.merge(Template.java:256)
	at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:422)
	at com.atlassian.velocity.DefaultVelocityManager.getEncodedBody(DefaultVelocityManager.java:77)
	at com.atlassian.velocity.DefaultVelocityManager.getEncodedBody(DefaultVelocityManager.java:61)
	at com.atlassian.velocity.DefaultVelocityManager.getEncodedBody(DefaultVelocityManager.java:56)
	at com.atlassian.jira.plugin.JiraResourcedModuleDescriptor.getHtml(JiraResourcedModuleDescriptor.java:109)
	at com.atlassian.jira.plugin.navigation.TopNavigationModuleDescriptor.getTopNavigationHtml(TopNavigationModuleDescriptor.java:83)
	at com.atlassian.jira.plugin.navigation.DefaultPluggableTopNavigation.getHtml(DefaultPluggableTopNavigation.java:23)
	at org.apache.jsp.decorators.general_jsp._jspService(general_jsp.java:432)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
	at com.opensymphony.sitemesh.compatability.OldDecorator2NewDecorator.render(OldDecorator2NewDecorator.java:46)
	at com.opensymphony.sitemesh.webapp.decorator.BaseWebAppDecorator.render(BaseWebAppDecorator.java:33)
	at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:84)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.seraph.filter.SecurityFilter.doFilter(SecurityFilter.java:211)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.security.auth.trustedapps.filter.TrustedApplicationsFilter.doFilter(TrustedApplicationsFilter.java:98)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.seraph.filter.BaseLoginFilter.doFilter(BaseLoginFilter.java:150)
	at lufthansa.jira.LSYHLoginFilter.doFilter(LSYHLoginFilter.java:69)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46)
	at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66)
	at com.atlassian.oauth.serviceprovider.internal.servlet.OAuthFilter.doFilter(OAuthFilter.java:71)
	at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74)
	at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.util.profiling.filters.ProfilingFilter.doFilter(ProfilingFilter.java:99)
	at com.atlassian.jira.web.filters.JIRAProfilingFilter.doFilter(JIRAProfilingFilter.java:16)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.jira.web.filters.ActionCleanupDelayFilter.doFilter(ActionCleanupDelayFilter.java:59)
	at com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.jira.web.filters.RequestCleanupFilter.doFilter(RequestCleanupFilter.java:53)
	at com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.johnson.filters.AbstractJohnsonFilter.doFilter(AbstractJohnsonFilter.java:71)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:350)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.gzipfilter.GzipFilter.doFilterInternal(GzipFilter.java:81)
	at com.atlassian.gzipfilter.GzipFilter.doFilter(GzipFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77)
	at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.core.filters.cache.AbstractCachingFilter.doFilter(AbstractCachingFilter.java:33)
	at com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.core.filters.encoding.AbstractEncodingFilter.doFilter(AbstractEncodingFilter.java:41)
	at com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31)
	at com.atlassian.jira.web.filters.PathMatchingEncodingFilter.doFilter(PathMatchingEncodingFilter.java:49)
	at com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.jira.web.monitor.ActiveRequestsFilter$PassToChainFilterFunc.doFilter(ActiveRequestsFilter.java:346)
	at com.atlassian.jira.web.monitor.ActiveRequestsFilter$DebugLogFilterFunc.doFilter(ActiveRequestsFilter.java:463)
	at com.atlassian.jira.web.monitor.ActiveRequestsFilter.doFilter(ActiveRequestsFilter.java:173)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.jira.startup.JiraStartupChecklistFilter.doFilter(JiraStartupChecklistFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.multitenant.servlet.MultiTenantServletFilter.doFilter(MultiTenantServletFilter.java:91)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.atlassian.jira.web.filters.JiraFirstFilter.doFilter(JiraFirstFilter.java:67)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
	at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
	at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
	at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:776)
	at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:705)
	at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:898)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
	at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.GeneratedMethodAccessor260.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at de.oio.agileplan.loader.AgilePlanBackendLoader$1.invoke(AgilePlanBackendLoader.java:123)
	... 166 more
Caused by: org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:695)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
	at $Proxy1055.getUserRights(Unknown Source)
	... 170 more

Is it make sense that something problem connected to Agile Plan? I mean with this script??

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2012

I dont think the error is related to the script post function. What happens when you create an issue ? is the duedate set automatically ? add some logging(or print messages) in the script . this will help in identifying where the error occurs.

Rumceisz April 10, 2012

Hi Mizan,

the DueDate isn't set when creating an issue.

How can we set logging in the script?

Regards,
Rumi

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2012

import org.apache.log4j.Category

log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") 
log.debug("PostFunction function running")

the above code will get the logger and now you can log after some points in the script ... this will help us to understand where the execution of the scripts stops.

and you can add a comment instead of typing your comment in the answer block given below. there is a small link above on the right to add comment. and there is a thumbs up next to the name to like the comment :D

Rumceisz April 10, 2012

Hi Mizan,

thank you for the logger code.

After inserting logger, I got a different error message:

2012-04-11 11:01:32,119 TP-Processor40 DEBUG u517593 661x400522x1 z56eq3 57.56.132.217 /secure/CreateIssueDetails.jspa [onresolve.jira.groovy.PostFunction] PostFunction function running
2012-04-11 11:01:32,222 TP-Processor36 ERROR u517593 661x400523x1 z56eq3 57.56.132.217 /browse/ADMIN-984 [backend.exception.impl.CallHandlerImpl] #41792: SystemException (2002)(please use InternalSystemException instead!)
SystemException: No user is given.(GUID=#41793 | Type=2002)

Does it mean, that I have to authenticate myself in the code too

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2012

I guess the script is running but due to something its getting terminated and the duedate is not set . try adding the below code at the end of the script

log.debug("Due date set to"+dueDate)

mutableIssue.store()

log.debug("postfunction completed")

Rumceisz April 10, 2012

Hi Mizan,

YOU ARE A GENIOUS!

I don't know yet what the last code means, but it works!

THANK YOU VERY MUCH!

I convinced that it was the most exiting issue in the last days:)

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2012

Welcome :)

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2012

Thanks :) hey you can vote up my posts :D

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2012

Well done Mizan ;-)

1 vote
uday ramakrishna April 5, 2012

I was unable to make any progress on this and gave up. Wish this was built in as a standard feature by JIRA. I really wonder if we made a completely wrong decision to buy this product.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 6, 2012

If you are willing to give up so soon without asking for any help, I really don't know what the right system is for you, but good luck in finding it.

1 vote
Rumceisz April 5, 2012

Hi Mizan,

I set this script as a post function but it didn't work for me. The only change I made was renaming the priority values because we renamed them in our JIRA.

I saved the script to a txt file, maybe this can be the bug?

Thanks in advance! (setduedate.txt)

Best Regards,

Rumi

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 6, 2012

The extension has to be .groovy so the system knows which interpreter to invoke.

0 votes
Deleted user October 20, 2017

Hi Mizan,

 

In  the script  you have mentioned I am facing an error in for loop section.

The error is 3 expressions are required for classic for loop you gave 4.

Please help me out here .

 

Thanks Karthik

0 votes
uday ramakrishna August 22, 2012

How would i go about about setting the priority value? I need to hardcode the value of priority. The user will be allowed to chose a due date he is interestd in and if that field is not empty i would like to do a setPriority to the status called Priority. Below is the code we have in the groovy script. What i want to be able to do is replace

if (dueDate != null && highPriority != null) { -- such that if dueDate is null which means if that field is not blank then set the priority color to red. we only have 2 states which is normal and priority. I know that we need to udpate the below code

mutableIssue.setPriority(highPriority.getGenericValue());

To achieve that but i am not completely sure what i need to pass to setPriorityfunction to flag the value as red Priority. Is it a boolean?

import com.atlassian.jira.issue.MutableIssue;

import com.atlassian.jira.issue.CustomFieldManager;

import com.atlassian.jira.config.ConstantsManager;

import com.atlassian.jira.issue.priority.Priority;

MutableIssue mutableIssue = (MutableIssue) issue;

def priority = mutableIssue.getPriorityObject();

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();

def dueDate = customFieldManager.getCustomFieldObjectByName("Priority Due Date");

def stt = customFieldManager.getCustomFieldObjectByName("Standard Turn Around Time");

if (priority == null || !priority.get("name").equals("Priority")) {

// pull the constant representing High Priority out of the database

ConstantsManager constantsManager = componentManager.getConstantsManager();

Priority highPriority;

for (Priority p: constantsManager.getPriorityObjects()) {

if (p.getName().equals("Priority")) {

highPriority = p;

}

}

if (dueDate != null && highPriority != null) {

log.info("GROOVY, due date is " + dueDate + " and its name is " + dueDate.getName()+ " and its value is " + dueDate.getValue(issue));

mutableIssue.setPriority(highPriority.getGenericValue());

mutableIssue.store();

log.info("GROOVY, I set the priority to " + highPriority);

}

}

0 votes
Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2012

The atlassian-jira.log which is in the Jira home directory .

0 votes
Rumceisz July 2, 2012

Hi All, hi Mizan,

we just upgraded our Jira instance from 4.3.4 to Jira 5 and the script doesn't work anymore!

We also upgraded our Script Runner plugin to version 2.0.6

The script is the following:

log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.debug("PostFunction function running")


 
// initializing the priority
 
 
def Sev1 = 1;
def Sev2 = 2;
def Sev3 = 3;
def Sev4 = 9;
  
 
// calender which returns the date according to the priority defined
 
private GregorianCalendar getDate(double roll){
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.set(Calendar.HOUR_OF_DAY,0);
        cal.set(Calendar.MINUTE,0);
        cal.set(Calendar.SECOND,0);
        cal.set(Calendar.MILLISECOND,0);
  
        for (int x=0;x<roll;x++){
                cal.add(Calendar.DAY_OF_MONTH,1);
        }
  
        return cal;
}
  
  
 
MutableIssue mutableIssue = (MutableIssue) issue;
def priority = mutableIssue.getPriority().getString("name");
def setDueDate = mutableIssue.getDueDate();
 //only set the dueDate if the date isn't already set (i.e. if it == null).
 
        GregorianCalendar cal;
 
         if(priority.equals("Sev 1 - Critical")){
                cal = getDate(Sev1);
        } else if(priority.equals("Sev 2 - Urgent")){
                cal = getDate(Sev2);
        } else if(priority.equals("Sev 3 - Normal")){
                cal = getDate(Sev3);
        } else if(priority.equals("Sev 4 - Low")){
                cal = getDate(Sev4);
	  }
        Timestamp dueDate = new Timestamp(cal.getTimeInMillis());
        mutableIssue.getPriorityObject();
        mutableIssue.setDueDate(dueDate);

log.debug("Due date set to"+dueDate)

mutableIssue.store()

log.debug("postfunction completed")

What could be changed because of the upgrade? I heard that it has to be set the groovy folder in the something Resource(??) but I don't where and what it is.

Can you please help?

Thanks in advance!

Rumi

Rumceisz July 2, 2012

additional info:

the problem must related to the upgrade: I tested the script in a Jira version 4.3.4 and works great!

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 2, 2012

The Api's have changed . Can you provide the logs ? add some more log statement so that we can identify easily where the problem is .

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2012

The atlassian-jira.log file which is in the Jira home directory

Rumceisz July 3, 2012

Hi Mizan,

OK! Just let me know please which log you mean?

Thank you!

Rumi

Rumceisz July 4, 2012

Hi Mizan,

it works now in Jira 5, I mend it.

If somebody change the Priority on the fly how can be achieved that the Due Date will change according to the new Priority?

Scripted field is precluded because Due Date is an existing default field.

I tried with Behaviour plugin - I just paste the code in the script field but nothing happened. Maybe it's not groovy to put there??

Can you please help?

Thanks in advance,

Rumi

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2012

If somebody change the Priority on the fly how can be achieved that the Due Date will change according to the new Priority?

The script is a postfunction , usually place on the create transition but if you want the due date to be changed according to the Priority on all transitions then you can set this as a postfunction on all transitions.

Rumceisz July 4, 2012

Yes, you're right. I guess a behaviour or scripted field solution can check every change in the Priority field and according to the change the Due Date would be updated. I guess...

What do you think?

Mizan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2012

Yes even that is posssible , which option suites your requirement ? The above script which runs with script runner OR a Behaviour which checks the priority field and if it changes sets the duedate accordingly ?

Rumceisz July 4, 2012

I opt the Behaviour because it seems to be easier.

What do you think?

Suggest an answer

Log in or Sign up to answer