Hi,
i'm trying to write a post-function script in order to update a custom value field depending a user reporte's group.
If the user belongs to "group1" then the field will have the value " value1"
Here is the script i've tried to write and can you please help me to make a correct version of it ?
I'm using Scriptrunner 5.5.7
Thanks in advance.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def customFieldManager = ComponentAccessor.customFieldManager
def SDG = customFieldManager.getCustomFieldObjectsByName("Société de gestion (SDG)").first()
def groupManager = ComponentAccessor.getGroupManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def config = SDG.getRelevantConfig(issue)
def options = optionsManager.getOptions(config)
if(groupManager.isUserInGroup(issue.reporter?.contains("XXX"))
{
def optionToSelect = options.find {it.value == "XXX"}
SDG.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(SDG),optionToSelect))
}
Hello @wajih zouaoui
try this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def customFieldManager = ComponentAccessor.customFieldManager
def SDG = customFieldManager.getCustomFieldObjectsByName("Société de gestion (SDG)").first()
def groupManager = ComponentAccessor.getGroupManager()
def issueManager = ComponentAccessor.getIssueManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def config = SDG.getRelevantConfig(issue)
def options = optionsManager.getOptions(config)
if (groupManager.isUserInGroup(issue.reporter, "group1")) {
def optionToSelect = options.find { it.value == "value1" }
issue.setCustomFieldValue(SDG, optionToSelect)
issueManager.updateIssue(issue.reporter, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
Hello Mark,
it works great and i want to thank you for your help.
Have a nice day.
Best Regards,
Wajih
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello again @Mark Markov ,
can we please create a script that it add automatically the right value on the custom field depending of the user group ?
It's like a behavior who try to find if there is a match with one group and a value from the custom field and then it choose the right value to fill on the custom field.
The custom field is not shown for users and it must be filled by the behavior script for view screen only.
FYI, every value on the field has the same as a user group.
cf value 1 = grp value1
..
Thanks a lot .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.