How to check/change text in a comment with behaviours from scriptrunner?

Kay Domschke August 16, 2021

Challenge:
When a colleague enters a text in the comment, the script runner should use a behavior to check whether he has written the word <men>. If this is the case, the word <men> will be replaced by <men / women>.

Condition:
Under no circumstances should the wrong word be found in history. Therefore, the listener and post function are unfortunately not an option.

Currently:
I can do this for all possible fields without any problems, only the comments bitch.

Question:
Does anyone have any idea how I can use behavior to make sense of the comments? I haven't found anything going that way.

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 16, 2021

Hi @Kay Domschke 

For your requirement, Behaviour may not be the correct approach.

The reason is that the Behaviour works only on specific screens, i.e. Create Issue, Update/Edit Issue, Assign Issue, and Workflow Transition screens.

For more information, please visit the Behaviour Limitation section in the ScriptRunner Documentation.


If you want the comment to be updated on the Workflow Transition screen, using the Behaviour, this is doable. For example:-

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def comment = getFieldById(fieldChanged)
def commentValue = comment.formValue.toString()

if (underlyingIssue != null) {
if (commentValue.contains("men")) {
def updatedValue = commentValue.replace("men", "men/women")
comment.setFormValue(updatedValue)
}
}

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

Below are a few test print screens:-

1)  First, the sample issue is created as shown below:-

image1.png

2) Next, the issue is transitioned to In Progress, and the transition screen appears as shown below:-

image2.png

3) Next, I am going to enter the word men into the comment field as shown below:-

image3.png

4) Finally, after entering the word men, once I click out of the comment field, as expected, the word updates to men/women as shown below:-

image4.png

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram

Kay Domschke August 16, 2021

That looks good. I understand the limitation of the Behaviors. If I could manage to switch to the editing screen when clicking on a comment, would a behavior also take effect? Then it would be ensured that nothing is written to the history. Would it work?

Since our colleagues do not only enter comments in the context of a status change, I unfortunately cannot take the path. I would also have to make sure that the same behavior applies when changing the comments.

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 19, 2021

Hi @Kay Domschke

To answer your question, I have tested the example code I provided in my previous comment, and it works on the Edit screen as well and not only on the transition screens

So, if the word man is added to the Edit screen's comment field, and you were to click out of the box, it will automatically change to man/woman

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram

Kay Domschke August 25, 2021

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

Yes, I tested it too. And it works great in edit mode. But if a comment is edited or recorded on the IssueScreen via the comment button, then unfortunately not. Here I am currently researching how I can get this resolved.

Christian Weimar March 5, 2024

@Kay Domschke : Dear Kay,

do you have a solution for your requirement?

We do have a very similar one...

Thanks for your reply,

Christian 

Kay Domschke
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!
March 5, 2024

Yes, we use the gdpr plugin.

Christian Weimar March 5, 2024

@Kay Domschke Thanks for your reply!

We are trying to manage it using script runner --> I will open a ticket in their system.

KR, Christian

Suggest an answer

Log in or Sign up to answer