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,299,894
Community Members
 
Community Events
165
Community Groups

Creating a Template Comments (Jira Service Management) does not work

Hi,

With Template Comments (Jira Service Management) in Scriptrunner I want to create a template comment that also prints the value of a custom field in the comment.

I've gone through the documentation at https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts/template-comments.html, but unfortunately I can't get the comment to work.

In Template I’ve the code

 

Dear $customerFirstName,

The name of the created Backoffice is $backofficeCf

Nice!

 

In Condition/Code I’ve

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager= ComponentAccessor.getCustomFieldManager()

def backofficeCf = customFieldManager1.getCustomFieldObjectByName("Backoffice name")

 

But I get the warning

Variable “customFieldManager” masks a binding variable of the same name.

I just don't understand how to solve this.

Anyone have any tips to solve it?

Thank you very much,

Regards Marco

1 answer

Hi @Marco Brundel

From your description, the reason why the code appears to be failing is that. 

1) You are initialising a bound variable, i.e. customFieldManager, as shown in the image below:-

default_comment_config.png

The example code provided in the documentation is a bit outdated and needs to be updated.

2) Whenever you want to pass the value from the Groovy code into the Comment template, you will need to use the config variable. However, you are directly passing the variable, i.e. backofficeCf, into your template in your case. This will not work.

Below is an example working code for your reference:-

import com.atlassian.jira.component.ComponentAccessor

def sampleList = customFieldManager.getCustomFieldObjectsByName("Sample List")[0]

config.sampleListValue = issue.getCustomFieldValue(sampleList) ?: 0

return true

Please note, this example code is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a print screen of the configuration:-

config.pngIf you observe the print screen above, I am passing the config.sampleListValue into the comment template i.e. 

The value selected is ${config.sampleListValue}

 Below is an example of the output:-

test1.png

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

329 views 2 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you