Can a custom field update trigger an issue to be created?

Mike Tyan January 15, 2019

Is there a way to use either ScriptRunner or build in Post Functions (or possibly a combination of the two) to have an issue be created based on updates to a custom field? 

 

2 answers

1 vote
Prakhar Srivastav {Appfire}
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 15, 2019

@Mike Tyan

You can write a listener for issueUpdate event. You can either use Scriptrunner or pure java to write such a listener.

I am providing links here to help you with it :

https://developer.atlassian.com/server/jira/platform/writing-jira-event-listeners-with-the-atlassian-event-library/

https://scriptrunner.adaptavist.com/latest/jira/listeners.html#_built_in_listeners

With post function it is not possible as post functions are triggered based workflow status transitions.

Hope this helps.

 

Regards

Prakhar

0 votes
Ismael Jimoh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 15, 2019

Yes it can.

Configure an event listener of type issue updated however this could break your system if not handled properly because if users ever make adjustments on the project or trigger any update, it could fire and create a ticket.

So the question would be why you want this and we can see if there are better alternatives we could suggest.

Mike Tyan January 16, 2019

@stroiai, i have the same concern, what about a trigger specific to a single custom field instead of any update on issue type? I guess this would involve SriptRunner running checks to confirm the change is on the desired custom field. 

 

The use case is that we have JIRA tracking our employees as 'HR Issues'. The request is when HR updates the 'Department' field, it will automatically create a HelpDesk ticket so our sys admins will have a task to update all systems that track a similar value. Email notifications were able to accomplish when we had a single sys admin but as our team grew and more agents came on board, we needed a more systematic process so that there's more accountability rather than an email that can be easily overlooked.  

Ismael Jimoh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 16, 2019

Offhand, I do not have a straight answer to this.

However, you could consider adding a condition to check if the field changed using something like is described here: https://community.atlassian.com/t5/Answers-Developer-Questions/Re-Notification-when-field-value-changes-from-quot-A-quot-to/qaq-p/495181/comment-id/32836#M32836

In your case, you would have 2 field values where you trigger your create based on:

Issue issue = event.issue
def
oldvalueField = customFieldManager.getCustomFieldObject('customfield_id')
def oldvalue= issue.getCustomFieldValue("customfield_id")
def newvalue = issue.getCustomFieldValue("customfield_id_of_department_field")

if(oldvalue != newValue){
//trigger the create issue method here.
createIssue()
}

static void createIssue(){
//Create issue goes here.


//At the end of create method update the oldvalue to the newvalue
issue.setCustomFieldValue(oldvalueField, newValue))
issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

}

This should achieve what you want because when you do the check and the oldvalue is still the same as newvalue then nothing would happen.

Remember though to set your oldvalue to newvalue at the end of the create issue operation.

Hope this helps. 

Suggest an answer

Log in or Sign up to answer