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"
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
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".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh sorry, I forgot to add asterisk character. This should be the correct form
def selectedCheckValues = checkField.getValue(issue)*.value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also updated the final code above.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For those values you need to use transientVars[
"issue"
]
instead of using issue as below
def mutableIssue =transientVars[
"issue"
]
mutableIssue.getCustomfieldValue()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, import in the second line was mistyped. It should be import, corrected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tuncay Senturk Our JIRA application consultants have advised that this is a risky way of achieving this approach.
Would you recommend another approach?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.