Forums

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

Jira Cloud Scriptrunner, on Create transition post function, how to link issue to query result issue

fhamel@addenergie.ca February 24, 2019

Hello Atlassian Community! This is a little challenge i have been tasked to resolve but have no experience what so ever in scripting and i am stuck at this step:

here is what we need:

When creating an issue, the user fills a custom fiel (CF [16900]) which represents the "serial number".  We have issue type "Serialnumber", where the serial number is in Summary field, and we would like the issue created to be linked to the matching "SerialNumber" type issue/Summary

Something like this in jql query language:

If

issuetype=serialnumber and Summary ~ "new issue's" CF[16900]

then

link issue to JQL query result issue

----------------

As a very "green" scripter, i have come up with this so far...but i'm pretty sure it's missing something or completely wrong...

Condition:

if issuetype=serialnumber and issue.field.summary = "new issue's" CF[16900]

 

If condition is met:

def cf='cf [11900]'
def query = '<SerialNumber>'
def issueId = issue.id

def link = post('/rest/api/2/issueLink')
  .header('Content-Type', 'application/json')
  .body([
  type: [ name: "Strong" ],
  outwardIssue: [ id: issueId ], // This is the issue that the link 'starts' at
  inwardIssue: [ key: 'EX-1' ] // this should be a variable representing the query result
])
.asString()
assert link.status == 201

Any help would be very much appreciated :)

Answer

1 answer

1 accepted

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
February 25, 2019

Hi Frédérique,

Thank you for your question.

I can confirm that we have an example script located here which shows how you can create an issue and link back to it on the create transition in the workflow as well as an example of linking two issues together here

I can confirm that we also have an example of how to extract the values from custom fields on an issue in the documentation pages located here.

These examples should help to show the structure that you will require to create the script that you require.

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

fhamel@addenergie.ca February 25, 2019

Hello Kristian,

Thank you for the script. The sript is almost what i need.  The tricky part, where i am stuck is, i need a way to define the target as "the result of a JQLquery".  This means it would be variable.  Can you help?

Frederique

Kristian Walker _Adaptavist_
Community Champion
February 25, 2019

Hi Frédérique,

I can confirm thatto run a JQL query inside  of your script you need to use the Search Rest API and I can confirm we have an example of  how to do  this inside  the documentation  in the page located here.

Regards,
Kristian

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events