Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

doAfterCreate { } Never Called from post function

Hi All,

I am trying to add a remote link to an issue when I create it using the "Clones and links "script.

I have add the function callback to my Additional actions part of the script but it is never called.  I have tried just setting basic fields to see that it is being executed but nothing ever happens.  I even tried to use the example to add a link to an existing issue,  pasted it and updated to match my existing issue and type.   The only example given and it doesn't even pass the static checker!   

 

So here is my code from the additional actions section - what am I doing wrong.  Setting the custom date field works fine outside the doCreateAfter but does nothing inside.   

I really want to just copy an external link from the creating issue to the cloned issue.  At this point I would be happy just to see any proof that the doAFterCreate ever gets called.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.issue.link.RemoteIssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager


def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def issueManager = ComponentAccessor.getIssueManager()

def cfield = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'LCM Phase'};
def fieldConfig = cfield.getRelevantConfig(issue)
def phase = "0"
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == phase }
issue.setCustomFieldValue(cfield, value)
issue.summary = sourceIssue.summary + ': Phase '+ phase +' Review'

// set the planned start date
def startfield = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Planned Start Date'};
def sourceStartField= customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Phase ' + phase + ' Start Date'};
issue.setCustomFieldValue(startfield, sourceIssue.getCustomFieldValue(sourceStartField))

// set the planned end date
//def endfield = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Planned Finish Date'};
//def sourceEndField= customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Phase ' + phase + ' End Date'};
//issue.setCustomFieldValue(endfield, sourceIssue.getCustomFieldValue(sourceEndField))


doAfterCreate = {


// set the planned end date
def endfield = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Planned Finish Date'};
def sourceEndField= customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Phase 0 End Date'};
issue.setCustomFieldValue(endfield, sourceIssue.getCustomFieldValue(sourceEndField))


}

   

1 answer

3 votes

Hello,

Do not use the doAfterCreate. Include the lines inside the do AfterCreate in your code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.issue.link.RemoteIssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager


def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def issueManager = ComponentAccessor.getIssueManager()

def cfield = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'LCM Phase'};
def fieldConfig = cfield.getRelevantConfig(issue)
def phase = "0"
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == phase }
issue.setCustomFieldValue(cfield, value)
issue.summary = sourceIssue.summary + ': Phase '+ phase +' Review'

// set the planned start date
def startfield = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Planned Start Date'};
def sourceStartField= customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Phase ' + phase + ' Start Date'};
issue.setCustomFieldValue(startfield, sourceIssue.getCustomFieldValue(sourceStartField))

// set the planned end date
//def endfield = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Planned Finish Date'};
//def sourceEndField= customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Phase ' + phase + ' End Date'};
//issue.setCustomFieldValue(endfield, sourceIssue.getCustomFieldValue(sourceEndField))



// set the planned end date
def endfield = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Planned Finish Date'};
def sourceEndField= customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Phase 0 End Date'};
issue.setCustomFieldValue(endfield, sourceIssue.getCustomFieldValue(sourceEndField))
 

Hi,  thanks for the response.  Yes the end date is outside after do create in my actual code.  But I need to add a remote link to the new issue and it will not work outside of the doAfterCreate{} and doesn't do anything inside the callback.  As far as I can tell doAfterCreate is never called.

I moved setting the custom field in to the doAfterCreate{} just so that I could verify that it is being executed.  I also tried changing the summary and other fields.  Nothing I do inside of doAfterCreate is ever executed.

So what I am trying to do is copy a remote link to a webpage from the source issue to the new issue.

I can put my code to copy the link into a separate post function and it will work there.  But is very clunky,  I have to go to my original issue,  search through all of the links to figure out which issues are the right type and are new,  get the linked issues,  add the remote link.

But if I can do it from the clone issue all of the information I need is available, I know it is a new issue and the correct type so I just need the call to create the remote link.  But this won't work until after the issue is created.

Did you try to log something in the doAfterCreate block with log.error("doAfterCreate")? Can you see these logs in the atlassian-jira.log file?

Suggest an answer

Log in or Sign up to answer
TAGS

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