Forums

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

Upgrading Jira Automation to ScriptRunner

JensH
Contributor
September 14, 2023

Hi
I have a Jira automation that creates a number of new tasks in a different project and links them back to the original issue. It clones the data into the new project, as shown in the partial screenshot:
Screenshot 2023-09-14 at 20.32.35.png

This solution has 2 problems:
It only works up to 14 or so new tasks (Antal Afskibninger) before i run into the 65 component limitation,
and now I have a new requirement that the list of new tasks comes from an external webcall where each object in an array should be created as new linked issue (before it was just a number i a field i could unroll). 

Without a loop construct in Jira Automation i cant see how i can iterate over the json array and thus I have been looking a ScriptRunner to see if that fixes my issues.

ScriptRunner in cloud seems to be sort of limited, as it can not plug in to the automation and thus I have to use a Script Listener.

First question: It is correctly understood, and not just en error by me, that ScriptRunner Cloud can not work directly in Jiras Automation framework?

Second question: For ScriptRunnner i have the feeling that i have all the components in a ScriptListener needed to solve this problem. Im struggling with putting them together for a solution.

I need the issue to be in a specific status:

issue.status="Klar til Ordrebehandling"

But i also need the links not to contain links that are "Afskibninger". Does anyone have idea how to do this?

For rest of script:
First i need to call an external web service and loop, i got that covered as:

baseUrl = "myUrl"
def response = get('BC13EXT/ODataV4/SalesOrders')
.queryString([ company: 'My company', '$filter': "Document_No eq 'SO123'"]) .header("accept", "application/json")
.header("Authorization", "auth string")
.asObject(Map)
.body
.value

response.each { item -> /*do stuff here*/ }

which works in the script console. For the do stuff part: 

Is the better way to encapsulate this in a jira automation triggered by an incoming webhook, where i give the parent issue key and and field data to this webhook.

Or

Is the better way to call first

POST rest/api/2/issue/

and then

POST rest/api/2/issueLink

for each that i need to have created and linked.

Is there any actual difference on any of these approaches. 

Thanks in advance for any clarifications :)

Best

Jens







 

 

1 answer

0 votes
Bill Sheboy
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 Leaders.
September 14, 2023

Hi @JensH 

I noted in your question this:

...the list of new tasks comes from an external webcall where each object in an array should be created as new linked issue (before it was just a number i a field i could unroll). 

Without a loop construct in Jira Automation i cant see how i can iterate over the json array...

With the Advanced Branch in automation rules, you can probably do what you ask, for up to 100 items.  For your scenario you would use the web response as a list to drive the branch, using the resulting data to create the issues.

You do not state to which issues you are linking, the source of the cloned issue, or the specific information used in the issue create, so those could be limitations if your rule has a lot more structure / decision making than you are showing.

Kind regards,
Bill

JensH
Contributor
September 14, 2023

Thanks for the reply Bill

I'm not aware of the Advanced Branch in automation rule, could something else. I will look that up.

There is not  a lot other decision making. Much of that is placed in other automations that trigger later. Structurally the Issues are the equal, but shown differently in the two projects via the a screen setup. 

Screenshot 2023-09-15 at 08.08.23.png

Thanks for the input
Best
Jens

JensH
Contributor
September 15, 2023

@Bill Sheboy I got the Advanced Branch idea to almost work. I have one issue that I cant figure out how to fix. 

The newly cloned issues should have the names like 1/N 2/N ...n/N .. N/N

I got the N part working by using {{webResponse.body.value.size}}

But inside the smart branch i need to know current iteration number, i have been trying to use {{index}} as: {{#webResponse.body.value}}{{index}}{{/}}

But that gives me all indices in each iteration so i end up with:
 012/3
 012/3
 012/3
as output. 

Naturally I would like the index to start with 1, but that's currently a minor issue compared to that I cant't get the index at all.

I can see in the forum that I'm not only one with this problem, but I can't seem to find a solution for this part.

Thanks in advance
Jens



Bill Sheboy
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 Leaders.
September 16, 2023

Without seeing the details of your advanced branch, I am guessing a bit here...

Having a sequential counter has be asked before, and the work-arounds depend on context / the structure of your branching.  Specifically, what information from the {{webResponse}} do you need inside of the branch to create the issues?

I have used a technique in the past with created variables to create the counters.  Please note that with branches (on more than one thing) in rules, the processing order is unknown because the items get processed in parallel and asynchronously.  So for this scenario the issues would be created with the names 1/N, 2/N...N/N but not created in that order in Jira.

JensH
Contributor
September 16, 2023

@Bill Sheboy  Thanks for replying.

I should have added the automation, sorry, here it is, including log and generated clones.

Thanks for help.
Best
Jens
Screenshot 2023-09-16 at 18.52.55.pngScreenshot 2023-09-16 at 18.49.40.pngScreenshot 2023-09-16 at 18.52.31.png

Bill Sheboy
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 Leaders.
September 16, 2023

Does your {{SalesLinie}} information in the branch source contain your counter values that you want in the cloned issue summary?

Can you please show what you are using to set the summary in the clone issue action?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events