Hello! I am new to scriptrunner and programming in general so I am struggling with how to achieve what I would like.
Here's my scenario-
I have issues within my project that have a custom date field "Billing Cycle Date".
I would like to run a workflow post function script which will take the billing cycle date, calculate what the next month is, and then append the name of the month into the summary.
So, let's say for a given issue:
Summary: Issue1
Billing Cycle Date: 3/5/2018
Upon workflow transition, postfunction script runs and sets Summary to "Issue1 - April"
I have spent multiple days trying to figure this out but nothing is working properly, any guidance would be greatly appreciated!
Could you provide one of your scripts, which is not working?
I figured this much out, which worked.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.UpdateIssueRequest
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
String field1Value = (String)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Cycle Date"))
issue.setSummary(field1Value)
But now, I need it to add exactly one month to the date (not 30 days), and then convert the month to the actual name and set it in the summary.
Not sure if that's possible, I'm exploring other options (combining multiple automation tasks or multiple fields).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.UpdateIssueRequest
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
java.sql.Timestamp field1Value = (java.sql.Timestamp)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Cycle Date"))
field1Value.setMonth(field1Value.getMonth() + 1)
issue.setSummary(field1Value)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your response, I truly appreciate it!
I am getting the following error, and am unsure what it means.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.UpdateIssueRequest
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
java.sql.Timestamp field1Value = (java.sql.Timestamp)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Cycle Date"))
field1Value.setMonth(field1Value.getMonth() + 1)
issue.setSummary(field1Value.toString())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is the error I got after using that script.
2018-03-10 11:03:38,576 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-03-10 11:03:38,577 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: RAR-4, actionId: 41, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896) at com.atlassian.jira.issue.Issue$getCustomFieldValue$6.call(Unknown Source) at Script119.run(Script119.groovy:7)
I modified the script to use getCustomFieldObject (with the customfield's id) instead of getCustomFieldObjectByName, and then got this error.
2018-03-10 11:13:02,566 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-03-10 11:13:02,581 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: RAR-4, actionId: 41, file: <inline script> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'August 24, 2018' with class 'java.lang.String' to class 'java.sql.Timestamp' at Script125.run(Script125.groovy:7)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is your Jira version?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My mistake, I apologize. That script ended up working, the field I was using it on was just a text field (I forgot I had tried a few other things before implementing the new script).
Now it is working great except it is putting the whole date and time into the summary. I would only like to put the name of the month.. for example if the date is June 1st, 2018, then only put "July"(next month) in the summary. Is that possible? I'm trying to research it myself right now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.UpdateIssueRequest
import java.text.SimpleDateFormat
SimpleDateFormat monthFormatter = new SimpleDateFormat("MMMM");
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
java.sql.Timestamp field1Value = (java.sql.Timestamp)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("CycleDate"))
field1Value.setMonth(field1Value.getMonth() + 1)
issue.setSummary(monthFormatter.format(field1Value))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi have the same issue:
any ideas? basically I need to set a value for the Description, but I don't now which command do i need for this, thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.