Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set Group Picker based on Checkboxes field in Post function

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

Hi @Harkins_ David 

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

Hi @Tuncay Senturk _Snapbytes_ 

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

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

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

I also updated the final code above.

Thanks

@Tuncay Senturk _Snapbytes_ 

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?

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

 

def mutableIssue = transientVars["issue"]

mutableIssue.getCustomfieldValue()

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])

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.

@Tuncay Senturk _Snapbytes_ 

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)

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

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)

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

Would you recommend another approach?

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
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,139 views 8 28
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you