Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using Scriptrunner to set a custom date field by adding a custom number field to today's date

Matt Noe
Contributor
March 26, 2025

I'm attempting to do some calculation on the fly to set an SLO date based on the date of the transition plus a custom number field value.  I think I'm close, but can't figure out what I need to improve.

Here is my console code I'm using to test:

 

 

def thisissue = Issues.getByKey("CLECOPS-7")
def dateplus = thisissue.getCustomFieldValue("Commitment SLO")as int
def today = new Date()
def slodateplus = today + dateplus

setCustomFieldValue("Vendor Processing SLO Date",new Date(slodateplus.getTime()))
And here is the result:

 

org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: Script_ca4bec07532a334a4674acf9a9009729.setCustomFieldValue() is applicable for argument types: (String, Date) values: [Vendor Processing SLO Date, Wed Apr 09 17:10:23 UTC 2025] at ConsoleScriptExecution1_groovyProxy.run(Unknown Source) Caused by: groovy.lang.MissingMethodException: No signature of method: Script_ca4bec07532a334a4674acf9a9009729.setCustomFieldValue() is applicable for argument types: (String, Date) values: [Vendor Processing SLO Date, Wed Apr 09 17:10:23 UTC 2025] at Script_ca4bec07532a334a4674acf9a9009729.run(Script_ca4bec07532a334a4674acf9a9009729.groovy:6) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:27) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:41) at ConsoleScriptExecution1_groovyProxy.run(Unknown Source) at com.adaptavist.sr.cloud.MainHandler.executeScript(MainHandler.groovy:416) at com.adaptavist.sr.cloud.MainHandler.processInput(MainHandler.groovy:365) at com.adaptavist.sr.cloud.MainHandler.access$1(MainHandler.groovy) at com.adaptavist.sr.cloud.MainHandler$_handleRequest_closure2.doCall(MainHandler.groovy:173) at com.adaptavist.sr.cloud.MainHandler$_handleRequest_closure2.call(MainHandler.groovy)

 

I'm assuming that my issue is that my custom date field is for the date only and not the time, and that the function I'm using is giving date and time, which is causing the script to error.

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 26, 2025

Hi Matt,

From the log message I am going to assume you are trying to update the field using a Post-Function.

What is the value that you intend to increment Date field with? Is it by number of days, i.e. the number field will specify the number of days to add to the date field?

If you could provide the information above, I will provide a sample for your reference.

I am looking forward to your feedback and clarification.

Thank you and Kind regards,

Ram

Matt Noe
Contributor
April 1, 2025

Hi Ram,

I'm actually running this in the script console for testing purposes, but I will use it in a post function.  

My case is that each vendor we deal with has a different SLO date.  Some could be 7 days, others 14, and possibly 30 for yet another.  Because it can be changed, I created a custom field to hold the number of days, and then on a transition, I will be building a sub-task with a due date of today plus that custom field value.

 

In my script above, "Commitment SLO " is my custom number field.  I'm grabbing today's date using "def today = new Date()" and trying to add them using "def slodateplus = today + dateplus" before trying to set the date custom field "Vendor Processing SLO Date"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events