Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

I need help in Scriptrunner postfunction OPEN

I am still new in Scriptrunner.

I want to create a subtask based on "created subtask" postfunction condition.

What I want to achieve is this:

I have project X --- when an issue in project X move to status "Review" it triggers a postfunction and create issue in project Y and link it to the issue project X.

When an issue is created in project Y it also triggers a postfunction and create a subtask based on the issue type specified.

I want to set a condition in my postfunction to say:
+Only create a subtask if the issue is linked to issue in project X.

Please help I dont know how to do it.
i have tried so many things but it didnt help

1 answer

Hi @Luvo Kautah Ncibane 

 

Please check this code and modify it if something will be wrong.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink

def condition=false

//def inwardLinkedIssues = ComponentAccessor.issueLinkManager.getInwardLinks(issue.id).each{
def outwardLinkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id).each{
def linkedIssue = it.destinationObject.key
if(linkedIssue.contains("LINKED_ISSUE_KEY")){
condition=true
}
}

return condition

What you need to know is check what type of link you use. If is outward link use this code as I pasted. If is inward link uncomment inwardLinkedIssues line and comment outwardLinkedIssues.

 

Let me know if it works

 

Regards,

Sebastian

Hi @Sebastian Krzewiński 

Thanks for your response but unfortunatelly it didnt help.

So I even tried this screen-grab.PNG

No luck still.

For some reasons, if i run the code in the  script console it works.

But when  I run it in the postfunction its not working

Which one you run in console and it works?

Can you describe where you put your post function?

Hi @Sebastian Krzewiński 

This is the code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink

def issue = ComponentAccessor.getIssueManager().getIssueObject("XXXX")
for(IssueLink link: ComponentAccessor.getIssueLinkManager().getIssueLinks(issue.getId())){ if(link.getIssueLinkType().getName().equals("RELATED")) return true } return false;

 it works in the console

I have my post function in the create transition.

scriptrunner.PNG

In cases like yours I make a "loop transition" and fire it usting fast-track transition.

In your case it will be loop from Todo to Todo. Then move Create subtask post function to loop transition. On Create transition add fast-track transition post function and mark that loop transitionn will be triggered without any condition.

Also you can hide loop transition from all users.

@Sebastian Krzewiński 

Do you perhaps have an example of what you are talking about.

I'm just confused.

Hi @Sebastian Krzewiński 

 

I only want to create subtasks based on the condtion that i have in the created subtask postfunction

Sorry that my answer wasn't clear enough.

1. Workflow should look like this:

1_workflow.png

2. On create transition you add fast-track transition post function (without any condition)

2_fast-track.png3_fast-track-config.png

3. On loop transition you add your subtask creation function

4_loop_transi.png

 

The reason that I do cases like this was because I saw that on create transition issue isn't be added to database with all needed information. So I must wait and run all needed function on second transition which is triggered from create transition.

From user perspective nothing is happend - issue after creation is in Todo status.

 

Regards,

Seba

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence Cloud

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

139 views 1 8
Read article

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