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
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
Thanks for your response but unfortunatelly it didnt help.
So I even tried this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Which one you run in console and it works?
Can you describe where you put your post function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you perhaps have an example of what you are talking about.
I'm just confused.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I only want to create subtasks based on the condtion that i have in the created subtask postfunction
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry that my answer wasn't clear enough.
1. Workflow should look like this:
2. On create transition you add fast-track transition post function (without any condition)
3. On loop transition you add your subtask creation function
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.