Summary

Sometimes, you need to create a lot of repetitive tasks with the same information. For this, it is possible using Script Jobs (old Escalation Services). The problem of Script Jobs is that depends on jira-administration support for the most cases.

The following solution allows the user to create a lot of related issues from one issue. This issue can be a issue template or a simple issue source.

To do it, we will do the following things:

  1. REST endpoint: We are going to write the code that will create the issues.
  2. Web Fragment: W will create the button that triggers the creation of issues.

Because this procedure can spend a lot of time, we are going to show one flag when the procedure finishes. You can check the following link for a simple example of flag in web fragment.

https://mraddon.blog/2017/03/29/jira-scriptrunner-rest-endpoint-web-fragment-example/

REST endpoint

REST endpoint is used to run codes that can be used from some different interfaces in JIRA, in this case the most important is know that, you can use REST endpoint always that you want to create a button to execute scriptrunner code.

Create a custom REST endpoint and define a REST endpoint in a script:

You can find the code in the following link.

https://github.com/MrAddon/Blog_Examples/blob/master/CreateGlobalRequests.groovy

This code creates a lot of issues depends on a custom field. The script foreach value of custom field create one issue. Set your own customfield with “at least” 2 options and your code will create 2 issues.


Keep care with the “Anonymous allowed” if you want to restrict the issue creation for only some allowed users. In this example, all the users can trigger this code.

Fragments

Now, we have the code that you can run, if you want to check if the code works you can do it. Please, follow the next link where in a simple example shows you how to do it.

https://mraddon.blog/2017/03/29/jira-scriptrunner-rest-endpoint-web-fragment-example/

To create the button, we are going to use Fragments, you can find it below REST endpoints.

Create Custom web item with the following information:

Note: Create Global Request

What section should this go in: operations-operations (1)

Key: create-global-request

Menu text: Create global request

Weight: 50

Condition:

Do what: Run code and show a flag (2)

Link: {jira_url}/rest/scriptrunner/latest/custom/CreateGlobalRequests?issueId=${issue.key} (3)

If you set correct the values, the Fragment will be created and ready to be used.

  1. In the following link you can find all the possible sections to set the button, in our case it has been set inside More of issue screen.
    https://developer.atlassian.com/server/jira/platform/
  2. We select the option of “Run code and show a flag” because inside REST endpoint there is defined the following code:

3. Remember that

Remember that you can try the REST Endpoint invoking this URL (you must be logged in JIRA through the browser to see the response):

Outcome

I hope you find it useful. I wait for you in the next post.

Posted by:juanjomarchal

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s