Assigning in postfunction

Hi everyone,

Nice to e-meet you all.

I'm having issues with a specific post-function(Clone an issue and link), I'm trying to create a issue link it to the original and have make it have a specific description and assignee.

There is a condition in place to not execute this in case some of the required variables are not filled in.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.security.Permissions;
import com.atlassian.jira.event.type.EventDispatchOption;
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
userManager = (UserManager) ComponentAccessor.getUserManager()
MutableIssue issue = issue
if (issue.getProjectObject().getKey() == 'OPS') {
	def cf_2 = customFieldManager.getCustomFieldObjectByName('Deployment date PROD')
	def cf_3 = customFieldManager.getCustomFieldObjectByName('Platform')
	val_2 = issue.getCustomFieldValue(cf_2).toString().split(" ")[0]
	val_3 = issue.getCustomFieldValue(cf_3).toString().split(" ")[0]
/*    
    if (cf_3 == 'Azure'){
        User usera = userManager.getUser('azure.team');
		issue.setAssignee(usera);
	}
*/        
	issue.setSummary(val_2 + ' deployment to PROD ' + val_3 + ' ' + issue.getSummary())
}

Everything seems to work as the output creates a ticket with for example:

2016-12-13 deployment to PROD Azure TESTCASE


I for the life of me can't get it to be assigned to the azure team however.
I've googled a few examples however I can't seem to find one that works for me, am I overseeing something?

Cheers for the help. 

4 answers

1 accepted

1 vote
Vasiliy Zverev Community Champion Dec 13, 2016

Check your if condition - there is custom field, but not its value. Here is refactired code:

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

if (issue.getProjectObject().getKey() == 'OPS') {    
    val_2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName('Deployment date PROD')).toString().split(" ")[0]
    val_3 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName('Platform')).toString().split(" ")[0]

    //val_3, but not custom field should be here
    if (val_3 == 'Azure'){       
        issue.setAssigneeId("azure.team");
    }

    issue.setSummary(val_2 + ' deployment to PROD ' + val_3 + ' ' + issue.getSummary())
}
0 vote

It's not clear how you are creating the issue - also you appear to be modifying the current issue...?

Hi Jamie,

The creation proccess in handled outside of the script, I execute this script on a workflow transition "Script workflow function : Clones an issue and links."

Where I have the script above set under "Additional issue actions".

Modifying the current issue before it's cloned would also solve my issue actually.

Thanks for the feedback, I got it to work.
It was a combination of me overseeing the if statement and I forgot the fact that the workflow of the created issue would auto assign to the reporter. 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

631 views 3 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you