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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,473
Community Members
 
Community Events
176
Community Groups

How to prevent subtask creation/issue creation using scriptrunner ?

Hi Team,

i need help for few of my questions and if its possible then how to implement them .

In JIRA workflow for my client ,i have created grrovy script that creates subtask when parent issue is created but now i wanted to add some constraints when a manual subtask is being created for a parent issue.

1. if autocreated subtask exists with same summary then manually new subtask  should not be created.

2. if my parent issue is makred to done then also it should not allow to create a new subtask manually.

3. parent issue is marked to done, once all subtasks are done then subtasks should not be allowd to move into other status even if transition from done to inprogress does exist.

 

Kinldy provide some code or scripts that can help me achiving above mentioned points.

No pluggings plz

 

2 comments

1.  Create a scripted validator that looks up to the parent issue, iterates over existing subtasks, and if it finds one with the new summary, fails validation

2.  You could build this into the same validator as 1 - an extra line to say "or parent status == done"

3. That's a condition, but similar to point 2.

The code for 3 to get you started:

  if ("Done".equals(issue.getParentObject().getStatus) ) { return false }

Issue sourceIssue = issue.getParentObject()
log.info "getParentObject :" + sourceIssue.getIssueType().getName()

//collecting AutoCreated subtask object
Collection allsubtasks = sourceIssue.getSubTaskObjects()

 

def Pdata = customFieldManager.getCustomFieldObjectByName("Please select the required sub-task")
LazyLoadedOption PdataField =(LazyLoadedOption) issue.getCustomFieldValue(Pdata)
def valueOfPdata = PdataField?.getValue()

if(issue.getParentObject().getStatus().getName()=='Done'){

code or validator should not create a subtask ???HOW??

   
}else{
   for(Issue allsubtask: allsubtasks) {
            NFRsubtaskSummary=allsubtask.getSummary()
           
                if (NFRsubtaskSummary== valueOfPdata)   {
     childissue.setSummary('Duplicate of '+NFRsubtaskSummary +'- Please Delete')   
      if (valueOfPdata == 'School')  {   
                     region.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(region), regionFieldValue.toString()),changeHolder)        
                     childPhase.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(childPhase), Inception.toString()),changeHolder)           
                     childHostCountry.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(childHostCountry), hostCountryFieldValue.toString()),changeHolder)        
                     }
                    break
    }else{

if (valueOfPdata == 'Home') {
childissue.setAssigneeId(user.name)
childissue.setReporterId(user.name)   
childissue.setSummary('Home')   
region.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(region), regionFieldValue.toString()),changeHolder)        
childPhase.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(childPhase),Construction.toString()),changeHolder)           
childHostCountry.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(childHostCountry), hostCountryFieldValue.toString()),changeHolder)        
}

 

This is the code i wrote , but i am not able to add or find some code/logic that helps not to create subtask

I think you've answered your own question.

In your code you have:

if(issue.getParentObject().getStatus().getName()=='Done'){

code or validator should not create a subtask ???HOW??

}else ...

You literally do nothing in that code block.  Creating a sub-task requires code.  If you don't want a sub-task, do nothing at that point.

Issue sourceIssue = issue.getParentObject()
log.info "getParentObject :" + sourceIssue.getIssueType().getName()

//collecting AutoCreated subtask object
Collection allsubtasks = sourceIssue.getSubTaskObjects()

 

def Pdata = customFieldManager.getCustomFieldObjectByName("Please select the required sub-task")
LazyLoadedOption PdataField =(LazyLoadedOption) issue.getCustomFieldValue(Pdata)
def valueOfPdata = PdataField?.getValue()

if(issue.getParentObject().getStatus().getName()=='Done'){

code or validator should not create a subtask ???HOW??

   
}else{
   for(Issue allsubtask: allsubtasks) {
            NFRsubtaskSummary=allsubtask.getSummary()
           
                if (NFRsubtaskSummary== valueOfPdata)   {
     childissue.setSummary('Duplicate of '+NFRsubtaskSummary +'- Please Delete')   
      if (valueOfPdata == 'School')  {   
                     region.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(region), regionFieldValue.toString()),changeHolder)        
                     childPhase.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(childPhase), Inception.toString()),changeHolder)           
                     childHostCountry.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(childHostCountry), hostCountryFieldValue.toString()),changeHolder)        
                     }
                    break
    }else{

if (valueOfPdata == 'Home') {
childissue.setAssigneeId(user.name)
childissue.setReporterId(user.name)   
childissue.setSummary('Home')   
region.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(region), regionFieldValue.toString()),changeHolder)        
childPhase.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(childPhase),Construction.toString()),changeHolder)           
childHostCountry.updateValue(null, childissue, new ModifiedValue(childissue.getCustomFieldValue(childHostCountry), hostCountryFieldValue.toString()),changeHolder)        
}

 

This is the code i wrote , but i am not able to add or find some code/logic that helps not to create subtask

When you return false, you block creating the subtask =) Because returning false tells the validation that the user shall not pass.

With assumption that you have chosen Simple scripted validator option

Comment

Log in or Sign up to comment