It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script or Automation to populate field

Hi All, 

I have been digging through community docs and the Adaptivist docs and can't quite seem to find what I am looking for.  

I have a new custom field that I want to populate based on the ticket type.  

Example - if it is a Story or Epic - then the custom field is = New Revenue

If it is a Bug or Tech Debt - then the custom field is = Maintenance

Any ideas on where to begin with this one? 

1 answer

Hi Davey,

Thank you for your question.

I can confirm that to achieve your requirement with ScriptRunner for Jira Cloud of setting a custom field when an issue is created based on its issue type that you would need to create a Script Listener which is configured to fire on the Issue Created event.

The script for your listener would need to have four if statements inside of it to check if the issue type is either Story , Epic, Bug or Tech Debt.

I can confirm that the example script located here shows how to check the issue type on lines 1 -3  and you can use this as a reference guide to help you create the conditions that you require to check the issue type.

The script will then need to have some logic written to set the value of the custom field inside each if statement to set it to the value that is required.

I can confirm that the Script Console page located here contains lots of example scripts on how to set different custom field types and you will be able to use these as a reference guide to help create the logic that you require to set the value inside of your custom field.

If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.

Regards,

Kristian

Kristian, 

Was that the correct Script Listener for the first part?   Your link is taking me to 

Store the Number of Subtasks in the Parent in the documentation.   

 

I had guessed I would need to write the script, but having difficulty since I do not know the specific language scriptrunner uses.   Is there a syntax guide or is this all based off the JIRA API documentation?  

Hi Davey,

Thank you for your response.

I can confirm that the link I sent you for the Store the Number of Subtasks in the Parent was because lines 1 to 3 of that script show how to check if the current issue type matches a specific issue type.

In this example, it is checking if it is not a subtask but you will be able to change this to remove the ! character and then to change where it specifies subtask to be the issue type that you need in order to create your if conditions.

As for a style guide, I can confirm that ScriptRunner uses Groovy and Jira Cloud uses the Atlassian rest API's so I would that you read through the Rest API Documentation published by Atlassian located here to get further details on how the rest API works, as well as through the ScriptRunner documentation site to get examples of how to perform common actions inside of Jira Cloud.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer
TAGS

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