not getting notification when assignee is changed

Aswini Vayyala June 21, 2016

Hi all,

I have tried many workarounds for setting a notification to the assignee. Nothing worked so far.

  • Added a post function to update 'assignee' field , used 'set custom field as function of other fields' to update assignee field and fired 'issue assigned' event in the transition - did not work
  • Added a post function to update 'assignee' field , used 'set custom field as function of other fields' to update assignee field and fired  a custom event  that sends a notification to 'current assignee and reporter' - did not work
  • Removed post function to update assignee field, added a transition screen to set assignee, added both 'issue assigned' and custom event to notify the current assignee

Is there a script I can use in post function that updates, edits and fires a relevant event to notify the assignee.


My workflow is all complete but am struck at the notification part. Please help

1 answer

0 votes
Vasiliy Zverev
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.
June 21, 2016

According to JIRA API when issue is updated it is possible to define is it nessesary to send a notification. 

Here is code for script postfunction (provided by SriptRunner plugin) to set assignee from custom filed:

import com.atlassian.jira.component.ComponentAccessor

issue.setAssignee(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fieldName").getValue(issue))

It should be executed before standard function "store to database"

Aswini Vayyala June 21, 2016

Hi Vasiliy,

 

Thanks for the script. I will test it. Can you please help me in going one step further and set assignee based on another custom field's value in the script?

Aswini Vayyala June 21, 2016

Hi Vasiliy,

I have created a custom field eg: "user" and I used your script in the transition to update assignee to the custom field "user" but assignee did not change on that transition.

import com.atlassian.jira.component.ComponentAccessor
 
issue.setAssignee(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fieldName").getValue(user))

 

I have included script at the very top, so that is the first action to take place

These are the transition steps

  • Script workflow function : A custom script will be run: from inline script.                                                
  •  Set issue status to the linked status of the destination workflow step.                                            
  •  Add a comment to an issue if one is entered during a transition.                                            
  • Update change history for an issue and store the issue in the database.                                            
  •     Re-index an issue to keep indexes in sync with the database.                                            
  •  Fire a Issue Assigned event that can be processed by the listeners

 

Vasiliy Zverev
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.
June 21, 2016

Here you are:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager

ApplicationUser userName =  ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("РФГ").getValue(issue)

UserManager userManager = ComponentAccessor.getUserManager();
ApplicationUser assignee;

switch(userName.getName()){
    case "vzverev": assignee = userManager.getUserByName("name")
    default: assignee = userManager.getUserByName("default assignee")
}

issue.setAssignee(assignee.getDirectoryUser())
Aswini Vayyala June 21, 2016

Tried this as well but assignee did not get set.

 

 

Vasiliy Zverev
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.
June 21, 2016

I works on my JIRA instance. Do you run it from postfunction or from Script console?

Aswini Vayyala June 21, 2016

I used in post function

Post function --> Script post function–> Custom script post function

Did not work.

 

What is the field "name" value : vzverev or Vasiliy zverev (username or fullname )?

Vasiliy Zverev
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.
June 21, 2016

Here should be username of user to assign to. For example vzverev or chubaka.

Suggest an answer

Log in or Sign up to answer