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

I need help in Scriptrunner postfunction OPEN

Luvo Kautah Ncibane September 27, 2019

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

Suggest an answer

Log in or Sign up to answer
0 votes
Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 28, 2019

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

Luvo Kautah Ncibane September 30, 2019

Hi @Sebastian Krzewiński 

Thanks for your response but unfortunatelly it didnt help.

So I even tried this screen-grab.PNG

Luvo Kautah Ncibane September 30, 2019

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

Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 30, 2019

Which one you run in console and it works?

Can you describe where you put your post function?

Luvo Kautah Ncibane October 1, 2019

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

Luvo Kautah Ncibane October 1, 2019

I have my post function in the create transition.

scriptrunner.PNG

Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 1, 2019

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.

Luvo Kautah Ncibane October 1, 2019

@Sebastian Krzewiński 

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

I'm just confused.

Luvo Kautah Ncibane October 1, 2019

Hi @Sebastian Krzewiński 

 

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

Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 1, 2019

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

TAGS
AUG Leaders

Atlassian Community Events