Add a description based on component value[scriptrunner]

arno June 24, 2024

Hi All

 I want to design a program to add the description of "remark" when component is equal to a certain value, but I find that no matter whether my component is a specific value, the operation will be triggered. My code is as follows


 

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS

 

def filed = getFieldById(getFieldChanged()
def com = getFieldById(COMPONENTS)
def name = com.getValue() as List
def text ="this is a test"
if ('test' in name){
  filed.setHelpText(text)
}

No matter whether my component is "test" or not, there will be "this is a test" in my remarks field. Is there a problem with my judgment? Could you please help me check the cause of the problem

2 answers

1 accepted

0 votes
Answer accepted
arno June 27, 2024

I have optimized the code, but I find that the last three lines of my code do not take effect. If I comment the variable "name", then the last three lines of my code can officially take effect. Can you tell me the reason why we need the variable "name" to make a judgment


import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FormField
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS



FormField componentsField = getFieldById(COMPONENTS)
List<ProjectComponent> components = componentsField.getValue() as List
def name = components.getAt(0).name



def com = getFieldById('commentLevel')
def text = """ this is a text  """


com.setHelpText(text)
arno June 30, 2024

This code is valid, the reason for the error is that I set a popup window, the popup window interface does not set components, so the components are empty, resulting in the code cannot be executed

0 votes
Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2024

Hey @arno 

Have you tried managing this with Jira's built in Automations? It seems like you probably don't need to use script runner for this.

If I understand your requirements properly it could be like the below:

  • TRIGGER: Field value changed
    • Fields to monitor: components
    • Change type: Any changes
    • For: all issue operations
  • IF: Add a condition: IF or ELSE
  • IF Condition 1: Issue fields condition
    • Field: Components
    • Condition: choose which is best, I'll use "contains any of"
    • Value: choose the component (e.g. Test)
    • THEN: Add an action: Edit issue
      • Choose fields to set: Description (or whatever field it is)
      • For the value input:
        • Whatever text you want to put in + {{issue.description}}
        • This will put the text in the description field before the original description, you could also go {{issue.description}} + whatever text
  • ELSE IF Condition 1: Repeat the IF Condition 1 for other components

If  you want it to be a comment instead, then choose "Comment on issue" instead of "Edit issue".

arno June 27, 2024

Hi @Jovin 

  Thank you for your reply

  Sorry, The method you provide can not achieve the effect we want. In fact, we need to set the comment prompt according to the module name, so that users can fill in the reason for closing the order according to the prompt when closing the order

Jovin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 28, 2024

Hey @arno 

Could you outline the journey of a user here? Like step-by-step of what you want the user to do and the code to do? We may still be able to achieve this via automation, but I don't have the actual user story.

e.g.

  1. User closes the order
  2. Jira prompts for a reason on transition
  3. etc. etc.
arno June 30, 2024

Hi @Jovin 

thank you for your reply

Automation does not do what I need, I have implemented this using scripts, this issue will be closed

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events