Forums

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

Use Keywords to automatically change comment visibility of Service Desk comments

Charlie
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 11, 2020

Hello there,

 

im starting to get used to scripting with behaviours. At the moment i have following problem:

I have 2 jira projects, 1 is a service desk project. im using a sync to keep both projects up to date. The only problem i have is that whenever a new comment is added, it gets synced an internal comment into my service desk project.

Now i thought of maybe using a keyword to decide which comment stays internal and which comment is public. 

 

So i thought of something like:

Pseudocode:

if(new comment is added to service desk issue) {

if(!comment contains keyword) set comment to public
}

i would be thankful for any help or if someone knows a workaround, that would be great aswell!

 

thank you very miuch

 

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Anton Chemlev - Toolstrek -
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 Champions.
January 29, 2018

Mmm, yes, it seems to be possible...

1) You can get previous Summary field value via https://docs.atlassian.com/software/jira/docs/api/7.0.4/com/atlassian/jira/issue/changehistory/ChangeHistoryManager.html

For example:

def changeItems = changeHistoryManager.getAllChangeItems(issue)

if (changeItems) {
def originalResolutionDate = changeItems.findAll {
it.field == "resolution"
}?.created.last()

 

2) And update custom field options via https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/issue/customfields/manager/OptionsManager.html. There's findByOptionId(Long optionId) method and setValue(Option option, String value) .

3) You can get appropriate field config via https://docs.atlassian.com/software/jira/docs/api/7.2.0/com/atlassian/jira/issue/fields/CustomField.html#getRelevantConfig-com.atlassian.jira.issue.Issue-

 

Hope this will help.

Praveen
January 29, 2018

Hi Anton, I have tried the above suggestion, however I am unable to use the setValue() method. It is throwing error. 

Error Message:  

 [Static type checking) - Cannot find matching method

Script356#setValue(com.atlassian.jira.issue.customfields.option.Option,

java.lang.String). Please check if the declared type is right and if the method

exists.

Possible solutions: getClass()  line 22, column 1.

 

Below is my code for your reference

 

def issue = event.issue as Issue

OptionsManager optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class);
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def newOptionValue = ComponentAccessor.getChangeHistoryManager().getChangeItemsForField(issue, "Name").collect {it.toString }.join(", ")
def oldOptionValue = ComponentAccessor.getChangeHistoryManager().getChangeItemsForField(issue, "Name").collect {it.fromString }.join(", ")


def cf = customFieldManager.getCustomFieldObjectByName("Custom_Field")
def fieldConfig = cf.getRelevantConfig(issue)
Option oldOption = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == oldOptionValue.toString()}

void setValue(oldOption, newOptionValue)
Marcus Yu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 14, 2020

Did you ever get this to work?

Slava Gefen
Contributor
May 8, 2023

It's working, thanks @Anton Chemlev - Toolstrek - !

0 votes
Anton Chemlev - Toolstrek -
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 Champions.
January 29, 2018

Hi,

What problem are you trying to solve? Could you please provide business-case?

You mean adding new options to select list on the fly? Or just choosing from existing ones?

Praveen
January 29, 2018

Hi Anton,

I have to update/rename an option from the set of already existing options. 

We already have a script to add new options in the form of issues (if a certain issue type is created its summary will be automatically be added as option). So if the user updates (changes the summary) the issue, the option should also change.

Ex:

IssueType: Fruits

Custom field Name: "Select Fruits"

Now if a new issue of type "Fruits" gets created, say for example "Apple" it will get added as an option to the Custom_field "Select Fruits" - this is working. But if someone edits the issue and changes from "Apple" to "Apples" it should Update the option also to "Apples" - this I'm unable to do.

Atmuri Naga Sumanth
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 10, 2022

@Praveen  we are also facing the same issue, Did you get solution to this? If yes, can you please help me over here..

Atmuri Naga Sumanth
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 10, 2022

I also need to update the existing custom filed option

TAGS
AUG Leaders

Atlassian Community Events