Forums

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

Using Script Runner to escalate the problem and add comments with a custom field Date/Time type

Prueba Cliente Edu March 24, 2021

JIRA Service Desk 4.13.2 (Jira Server)

Hello,

I am using "ScriptRunner >> Jobs >> Escalation service" to add a comment to a group of issues with a JQL Query. I would like to add the value of a custom field of type Date / Time to the comment, but in "Additional issue actions" I can only add a comment:

issueInputParameters.setComment ('Write your comment here')

 

Captura.JPG

How can I also add a Date / Time type field to the comment?
Someone could help me?

Thanks

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
March 24, 2021

Hi @Prueba Cliente Edu I think you just need to

  • get custom field value
  • create comment String which contains custom field's value
  • set the comment to issueInputParameters

It should be somethinkg like:

def dateCustomField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName(fieldName)
def dateCustomFieldValue = issue.getCustomFieldValue(dateCustomField)
def simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
def dateAsString = simpleDateFormat.format(dateCustomFieldValue)

issueInputParameters.setComment (dateAsString)
Prueba Cliente Edu March 25, 2021

Hi, @Martin Bayer _MoroSystems_ s_r_o__ 

Thank you very much for your answer.

I have done what you told me, but it gives the following error:

Captura.JPG

Also, if possible, I would like to include a free text in the comment, in addition to the date value. How could I do it?

Something like this: The date is: <dateAsString>

Thanks again.

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
March 27, 2021

Hi @Prueba Cliente Edu , you need to

import java.text.SimpleDateFormat

and fix your code new simpleDateFormat to new SimpleDateFormat

Like Prueba Cliente Edu likes this
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
April 8, 2021

Hi @Prueba Cliente Edu did it work for you?

Prueba Cliente Edu April 8, 2021

Hi, @Martin Bayer _MoroSystems_ s_r_o__ , Now I have other errors:

Error1.jpgError2.jpg

I am barely aware of "groovy", sorry for the inconvenience.

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
April 8, 2021

Hi @Prueba Cliente Edu you just need to add another import


import com.atlassian.jira.component.ComponentAccessor

It will solve first error. The other error is only static type check of groovy and it will work without resolving it.

The issue here is that Groovy does not use object types as strictly as Java do...

Prueba Cliente Edu April 8, 2021

I have already modified it, but I have another error when executing:

 

2021-04-08 11:38:36,262 ERROR [jobs.EscalationService]: Escalation Service (Prueba Escalada) failed for issue BBVA-10
groovy.lang.MissingPropertyException: No such property: created for class: Script25
at Script25.run(Script25.groovy:4)

 

My groovy code that I am running is this:

 

import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat

def dateCustomField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName(created)
def dateCustomFieldValue = issue.getCustomFieldValue(dateCustomField)
def simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
def dateAsString = simpleDateFormat.format(dateCustomFieldValue)

issueInputParameters.setComment (dateAsString)

 

Can you help me, please?

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
April 8, 2021

Yeah, your code

def dateCustomField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName(created)

is wrong. You need to set custom fields name as the parameter of the method getCustomFieldObjectByName. It should be something like

 def dateCustomField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Name of my field")
Prueba Cliente Edu April 8, 2021

ok, thank !!

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
April 8, 2021

@Prueba Cliente Edu does it work from beginning to end now :)?

Suggest an answer

Log in or Sign up to answer