Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,120
Community Members
 
Community Events
185
Community Groups

Post-Function ScriptRunner script to update summary with name of following month

Edited

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!

1 answer

1 accepted

2 votes
Answer accepted
Alexey Matveev
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.
Mar 05, 2018

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

Alexey Matveev
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.
Mar 08, 2018 • edited

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)

Thank you for your response, I truly appreciate it!

I am getting the following error, and am unsure what it means.

scriptrunnererror.PNG

Alexey Matveev
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.
Mar 09, 2018
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())

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)
Alexey Matveev
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.
Mar 10, 2018

What is your Jira version?

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.

Alexey Matveev
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.
Mar 10, 2018
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))

Hi have the same issue:
image.png

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

Did you ever find out? I am looking to do the same.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events