groovy condition to check Assignee field is unassigned

Kiranped October 28, 2021

My Jira was upgraded from 7.13.x to 8.5.x

// below post-function if loop returns false in 7.13.x

if(issue.assignee){}   => false

 

// Post Jira upgrade, below post-function if loop returns true in 8.5.x

if(issue.assignee){}   => true

 

on both versions, create screen assignee field is 'automatic'.

I have a post-function to update assignee when unassigned based on few field selection.

 

 

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 28, 2021

Hi @Kiranped

You mentioned:-

I have a post-function to update assignee when unassigned based on few field selection.

Is this post-function working or not?

Could you please share the current post-function code that you are using?

Thank you and Kind Regards,

Ram

Kiranped October 29, 2021

 


import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.component.ComponentAccessor


CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager()

def cfProgram = "customfield_18940"
def cfLocation = "customfield_23202"
def cfPlatform = "customfield_23203"
CustomField program = cfManager.getCustomFieldObject(cfProgram)
CustomField location = cfManager.getCustomFieldObject(cfLocation)
CustomField platform = cfManager.getCustomFieldObject(cfPlatform)
def programval = (String)issue.getCustomFieldValue(program)
def locationval = (String)issue.getCustomFieldValue(location)
def platformval = (String)issue.getCustomFieldValue(platform)

if(!issue.assignee){   // even though Asignee is not assigned as shown below - returning F
if(programval in ["Crex"] && locationval.contains("Prototyping")){
setAssigneeFunction( "1000272218")
}else if(programval in ["Optimus"] && locationval.contains("Prototyping")){
if(platformval == "HAPS70"){
setAssigneeFunction( "1000265841")
}else if(platformval in ["Palladium", "Protium"]){
setAssigneeFunction( "7329167")
}
}else if(programval in ["FW Unification"] && locationval.contains("Prototyping")){
setAssigneeFunction( "1000270976")
}else if(programval in ["General Lab"]){
if(locationval in ["Milpitas - Prototyping Lab"])
setAssigneeFunction( "1000255593")
else if(locationval in ["Bangalore - Prototyping Lab"])
setAssigneeFunction( "1000272218")
else if(locationval in ["Longmont - Prototyping Lab","Other - Prototyping Lab"])
setAssigneeFunction( "1000208616")
}else (programval in ["Heera"] && locationval.contains("Prototyping")){
setAssigneeFunction( "1000265841")
} }

def setAssigneeFunction(String username){
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName(username)
issue.setAssignee(user)
}


Assignee.JPG

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 1, 2021

Hi @Kiranped,

For your requirement, you should try something like this:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

def mutableIssue = issue as MutableIssue

def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def userManager = ComponentAccessor.userManager
def processType = customFieldManager.getCustomFieldObjectsByName('Process Type').first()
def processTypeValue = processType.getValue(mutableIssue).toString()

def assignee

if (processTypeValue == 'Solution Design') {
assignee = userManager.getUserByName('ram')
} else if (processTypeValue == 'Development') {
assignee = userManager.getUserByName('max')
} else if (processTypeValue == 'QA') {
assignee = userManager.getUserByName('admin')
}

mutableIssue.setAssignee(assignee)
issueManager.updateIssue(assignee,mutableIssue, EventDispatchOption.DO_NOT_DISPATCH,false)

Please note, the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

The main thing missing in your code is this:-

issueManager.updateIssue(assignee,mutableIssue, EventDispatchOption.DO_NOT_DISPATCH,false)

You need to include this to ensure that the update to the issue via the post-function is triggered.

Below is a print screen of the Post-Function configuration:-

post_function_config.png

 

Below are a few test print screens:-

1. If the Product type selected is Solution Design, as shown below:-

test1.png

The Assignee is set to Ram Kumar as shown in the image below:-

test2.png

2. If the Product type selected is Development, as shown below:-

test3.png

The Assignee is set to Max Peterson as shown in the image below:-test4.png

3. If the Product type selected is QA, as shown below:-

test5.png

The Assignee is set to Admin as shown in the image below:-test6.png

 

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram

Kiranped November 8, 2021

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thanks for your response.

The requirement here is:

if(issue.assignee)  // it should return true only if the assignee field is updated on create screen OR it should return False in-case assignee field is not updated or left 'automatic'

 

The problem is:  issue.assignee // returning true in all case

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 15, 2021

Hi @Kiranped

 

If you want to check whether the issue assignee has been selected on the Create screen, you need to use the Behaviour instead of the Post-Function to validate it.

 

Thank you and Kind Regards,
Ram

Suggest an answer

Log in or Sign up to answer