Set Group Picker based on Checkboxes field in Post function

David Harkins
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.
February 4, 2021

I have the following working:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()

def singleGroupCf = customFieldManager.getCustomFieldObjectByName("Department")

def group = groupManager.getGroup("Services")

issue.setCustomFieldValue(singleGroupCf, [group])

 

How can I set the group, based on a currently selected checkbox field called "Assign Department"

1 answer

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 7, 2021

Hi @David Harkins 

Welcome to the community,

As far as I understand, you have a checkbox custom field named "Assign Department" and you want to check its value before updating the group custom field.

Below you can use the code to get the value of a checkbox

 

def checkField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Assign Department");
def selectedCheckValues = checkField.getValue(issue)*.value
 
if ("check value" in selectedCheckValues) {
   // Place your code here to update the group field
}

 I hope it was helpful

Cheers

Tuncay

David Harkins
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.
February 8, 2021

Hi @Tuncay Senturk 

Many thanks for your response, I've attempted this, but getting some errors displayed in the Post Functions editor.

Instead of checking for each possible entry, as the list could grow, the Department can be set to the same value selected in "Assign Department".Annotation 2021-02-08 172434_2.pngAnnotation 2021-02-08 172434.png

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 8, 2021

Oh sorry, I forgot to add asterisk character. This should be the correct form

def selectedCheckValues = checkField.getValue(issue)*.value
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 8, 2021

I also updated the final code above.

Thanks

David Harkins
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.
February 10, 2021

@Tuncay Senturk 

I have this working to fashion now, Thanks :-) 

Have it configured on a Transition post function, it works, but is setting the Department to the previous value, not the new value being specified.

I assume I will need to adjust the order of the post functions?

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 10, 2021

For those values you need to use transientVars["issue"instead of using issue as below

 

def mutableIssue = transientVars["issue"]

mutableIssue.getCustomfieldValue()
David Harkins
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.
February 12, 2021

Do these need to replace existing line?

Newbie with Script Runner here.

What I have so far:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()

def singleGroupCf = customFieldManager.getCustomFieldObjectByName("Department")

def checkField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Assign Department");
def selectedCheckValues = checkField.getValue(issue)*.value

def group = groupManager.getGroup(selectedCheckValues)

issue.setCustomFieldValue(singleGroupCf, [group])
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 16, 2021

Try this one below;

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

def mutableIssue = transientVars["issue"]
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupManager = ComponentAccessor.getGroupManager()

def singleGroupCf = customFieldManager.getCustomFieldObjectByName("Department")

def checkField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Assign Department");
def selectedCheckValues = checkField.getValue(mubaleIssue)*.value

def group = groupManager.getGroup(selectedCheckValues)

issue.setCustomFieldValue(singleGroupCf, [group])

I haven't tried it, I just updated your snippet, so there might be errors.

David Harkins
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.
February 16, 2021

@Tuncay Senturk 

Thanks for the assist, still getting some errors, will keep looking through notes at my side,

2021-02-16 12:45:06,117 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue #### for user '####'. View here: https://####.####.com/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=ITIL+Incidents&descriptorTab=postfunctions&workflowTransition=131&highlight=1
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.ımport() is applicable for argument types: (Class) values: [interface com.atlassian.jira.issue.MutableIssue]
Possible solutions: split(groovy.lang.Closure)
 at Script214.run(Script214.groovy:2)
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 16, 2021

Yeah, import in the second line was mistyped. It should be import, corrected.

David Harkins
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.
February 16, 2021

Also corrected the type

def selectedCheckValues = checkField.getValue(mubaleIssue)*.value

Should be

def selectedCheckValues = checkField.getValue(mutableIssue)*.value

Still getting the following:

groovy.lang.MissingMethodException: No signature of method: com.google.common.collect.SingletonImmutableList.getValue() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [LOGS-6826]
Possible solutions: getClass()
 at Script229.run(Script229.groovy:16)
David Harkins
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.
February 25, 2021

@Tuncay Senturk Our JIRA application consultants have advised that this is  a risky way of achieving this approach.

Would you recommend another approach?

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 25, 2021

Why do they think it is a risky way? It is not risky unless you put the post function in the right order.

On the other hand, I do not know any other way of getting the new value of an issue field which is changed via the transition screen during the transition. Since the change was not persisted, you can't get the value unless you use my mutableIssue solution.

Suggest an answer

Log in or Sign up to answer