I want to change custom field value when assignee is changed

Hi Experts,

I want to change custom field value if someone change the assignee of issue. Kindly refer me some sample code or example.

Thanks

Are you looking for a front end solution or back end app?

1 Like

I am looking for the backend solution.

  1. Start from writing a custom listener to issue assignee change
  2. Update the custom field in listener
    Below link are not accurate solution but will get you close enough.
    https://community.atlassian.com/t5/Answers-Developer-Questions/Update-an-issue-field-in-a-listener-changes-are-not-made/qaq-p/566449
    https://community.atlassian.com/t5/Answers-Developer-Questions/How-do-I-programmatically-set-values-for-custom-fields-of-type/qaq-p/485784
1 Like

Hi @saurabh.gupta,

I have implemented issue update listener but when I change assignee value it is calling twice and if I update any other filed except assignee it is working fine. Do you have any idea why it is calling twice. Can we implement specific event for assignee field of issue?

@EventListener
	public void onIssueEvent(IssueEvent issueEvent)  {
	    Long eventTypeId = issueEvent.getEventTypeId();
	  
	    if(eventTypeId.equals(EventType.ISSUE_UPDATED_ID)){
	    	updateIssue(issueEvent);
	    }
	}

I don’t have idea why its calling it twice(maybe issue is getting updated twice through post-functions implemented through UI)
Have you tried EventType.ISSUE_ASSIGNED_ID
Great work btw.

I assume your updateIssue method ends up calling IssueService.update(...). There are several overloaded update methods in IssueService, one of which accepts am EventDispatchOption. You might perhaps like to pass EventDispatchOption.DO_NOT_DISPATCH to prevent a consequential event from being published.

Thanks @david.pinn now it is working fine.
Can we implement on ISSUE_ASSIGNED event only so my code will not execute on issue update event. It will make more efficient my code.

If i change assignee also in issue it will return only 2 as eventTypeId. Is there something I am missing? How it will return 3 as eventTypeId. If returns 3 on assignee changes then i can easily handle with EventType.ISSUE_ASSIGNED_ID.

@EventListener
	public void onIssueEvent(IssueEvent issueEvent)  {
	    Long eventTypeId = issueEvent.getEventTypeId();
	  
	    if(eventTypeId.equals(EventType.ISSUE_ASSIGNED_ID)){
	    	updateIssue(issueEvent);
	    }
	}

No, I don’t believe so. It’s one IF statement, which won’t slow you down too much. :slight_smile:

You can call IssueEvent.getChangeLog() to learn what has been changed in the issue. The getChangeLog() method returns a GenericValue, which is inconvenient, but I think you’ll be able to find your way around if you put a breakpoint in your code, and examine the actual runtime GenericValue value. You can use the OfBizDelegator to interrogate the change log contents.