Forums

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

Post Function to Create a New Issue and Set Link Value

Kmmaughs
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.
August 12, 2020

Hey Community,

I'm trying to use a post function to create a new issue during a workflow transition. Here's my set up:

First Task: ABC-1

During a transition of this First Task, a new issue gets created with a Linked Relationship "is blocked by." I'll call this one the Second Task, ABC-2.

When this Second Task is marked Done, I want a third issue to be created. I'll call this the Third Task, ABC-3. This Third Task should be created with a link to the First Task (as "blocks"). 

So ABC-1 is blocked by ABC-2. When ABC-2 is transitioned to Done, it creates ABC-3, which also blocks ABC-1. So ABC-1 cannot be done until these other two are finished. 

The issue I'm having trouble with is getting ABC-3 to be created with a link to ABC-1. I ended up storing the Parent Link value (ABC-1) on ABC-2, so I had some way to track it. 

I set up a Post Function for ABC-2, and here's what it looks like:

 

// Set the Issue Summary
issue.summary = "Review: ' + sourceIssue.summary

// Set the Assignee
issue.assigneeId = 'firstname.lastname'
issue.reporter = sourceIssue.assignee

// Set the Original Estimate of the New Ticket to 30 Minutes
issue.setOriginalEstimate(30*60)

// Grab the Parent Link of this Ticket
def ParentLink = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Parent Link'}
issue.setCustomFieldValue(ParentLink, sourceIssue.getCustomFieldValue(ParentLink))

// Use the Parent Link to Create a Link of this new issue to the original Parent
linkIssue(issue.id, ParentLink,"blocks")

I have an error on that last line with no help indicating the problem. Any advice?

1 answer

1 accepted

0 votes
Answer accepted
Ste Wright
Community Champion
August 15, 2020

Hi @Kmmaughs 

I'm not sure how to do it via Post Functions - but it might be possible via Automation?

It looks like you need:

  • When ABC-1 is transitioned from Status A to Status B, create ABC-2 and link it to ABC-1
  • When ABC-2 is closed, create ABC-3 - and link it to ABC-1
  • Stop ABC-1 from being closed if ABC-2 / ABC-3 remain open

The last bullet might be best managed via a workflow condition - via automation it would be a status reversal, rather than stopping a user from making the transition.

If you would consider Automation - let me know if the rules above are correct and if there is any other information which might be beneficial - for example, is there a status that ABC-1 transitions to after ABC-3's creation which could be used to stop ABC-4 being created (as rule might just create a new issue each time a related issue is closed).

Ste

Kmmaughs
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.
August 17, 2020

Hey Stephen,

I have JSU Automation installed; I hope this is what you were referring to: https://marketplace.atlassian.com/apps/5048/jsu-automation-suite-for-jira-workflows?hosting=server&tab=overview

Looking at your bulleted list, I have the first one working and done (with Automation). The second bullet is the one I'm struggling with. And the third one, I know how to do but am not currently enforcing the rule.

So it's really bullet two. How can I create that ABC-3 issue with a link to ABC-1?

Thanks in advance for taking a look at this.

-K

Ste Wright
Community Champion
August 17, 2020

Hi @Kmmaughs 

So this is how I built both rules (for reference).

Rule 1:

  • Trigger: Issue Transitioned - FROM Status A TO Status B
  • Action: Create Issue - set Linked Issues: blocks Trigger Issue, set Labels: First_Task

Rule 2:

  • Trigger: issue Transitioned - TO Done
  • Condition: Issue Fields Condition - Labels (Field) contains none of (Condition) Last_Task (Value)
  • Condition: Issue Fields Condition - Labels (Field) contains any of (Condition) First_Task (Value)
  • Action: Create Issue - set Labels: Last_Task, set Linked Issues: Copy value from "Trigger Issue" (you can access "Copy from..." from the 3-dots button)

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

This is how its built:

  • Rule 1 creates the initial related task - Task 1
  • When Task 1 closes, it activates Rule 2
  • The conditions in Rule 2 avoid the rule activating to create Task 3 (i.e if Task 2 transitions to DONE) and ensures it only creates an issue when Task 1 closes (as opposed to any issue in the project being transitioned to DONE)
  • These conditions require a unique identifier to be set during Task 1/2's creation - I used a label (First_Task / Last_Task); you can change this if you prefer

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

You can refine these rules of course - for example, if there is a condition for running Rule 1 (eg. a specific issue type). 

Let us know if this is sufficient! If not and there is something you'd like to modify, let us know and I'll be happy to assist further :)

Ste

Kmmaughs
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.
August 18, 2020

Hmm....I don't have a three dots button anywhere. 

Create Linked Issue 1.PNGCreate Linked Issue 2.PNG

Kmmaughs
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.
August 18, 2020

For Rule 2, it's that last bullet - I cannot find a way to set the Linked Issue value from this Task 3 to Task 1. 

Ste Wright
Community Champion
September 6, 2020

Hi @Kmmaughs 

To be clear, I'm using Automation for Jira (native feature) - not JSU Automation Suite.

For example, to access project-level automation:

  1. On your Project, go to Project Settings > Automation
  2. Select the blue "Create Rule" button to start creating

See more on Automation for Jira in the Knowledge Base.

Ste

Kmmaughs
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 9, 2020

Ahh, thank you for clarifying; this totally worked! I ended up storing the Parent Link as a custom field value (rather than using the Label field), so when I set up the Automation rule, the condition checks if the custom field is not empty.

For others reading through, the rule was set up in this manner:

Automation Rule.png

And then when the issue was created, I copied and set various fields. One field I had to set was a Multi-Level Cascading Select value, which I struggled with a bit, but ultimately got it set by using this format in the Additional Fields section:

{
"fields": {
"customfield_11111" : [{ "id": "11111"}] }
}

Thanks so much, again!

Like Ste Wright likes this
Ste Wright
Community Champion
September 9, 2020

Hi @Kmmaughs 

No worries - thanks for sharing your solution with the Community, this will help other users who locate this question!

I really like the way you utilised the "Parent Link" here, great option!

Ste

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events