Hi Team,
I'm Wondering that In my Jira I have 3 Groups(X,Y,Z) each group contains like 10 users.
Group X : a,b,c,d
Group Y : e,f,g,h
Group Z : i,j,k,l
So in a project if any user is creating a issue if that issue is assignee to " a " user the group filed has to automatically update to Group "X".
same like that depends up on assignee user the group filed has to change to user related group
is this Possible if it is can you please suggest me how to do this
Thanks,
Kumar
You should be able to write a scripted listener that runs on issue create, update and assigned, looks at the assignee and works out which group to update the field with.
You do have one possible logical problem to think through - imagine user N is in groups Y and Z - which group goes in your group field?
Hi @Nic Brough -Adaptavist- thanks for your response,
I have 3 groups and in those groups we don’t have any users in two groups .
the X group will create the issues and then Y and Z group users will work on those issues most of the time
only in some cases the X group will assigne them self
On one transition of workflow I added a post-function if any user execute that transition that user will be current assigne of that issue
so here i’m Trying when ever assignee changes I have a group picker field that has to change automatic to user belonged group
can you please help me in script
thanks,
kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have found an similar script in atlassian community I have modified that script can you please help with the script if it is wrong
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def currentIssue = event.issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def assigneeField = customFieldManager.getCustomFieldObjectByName("assignee");
def assignmentgroupField = customFieldManager.getCustomFieldObjectByName("Assignment Group")
def assigneeFieldValue = currentIssue.getCustomFieldValue(assigneeField);
def assigneeFieldValueString = assigneeFieldValue.toString()
def optionsManager = ComponentAccessor.getOptionsManager();
def changeHolder = new DefaultIssueChangeHolder();
if (assigneeFieldValueString == "kumar") {
def assignmentgroupFieldOption = optionsManager.getOptions(assignmentgroupField.getRelevantConfig(currentIssue)).find {it.value == "Incident-Developer1"};
assignmentgroupField.updateValue(null, currentIssue, new ModifiedValue(currentIssue.getCustomFieldValue(assignmentgroupField), assignmentgroupFieldOption), changeHolder);
}
here is the Logs :
2019-01-16 16:40:58,911 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2019-01-16 16:40:58,912 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896) at com.atlassian.jira.issue.Issue$getCustomFieldValue$5.call(Unknown Source) at Script930.run(Script930.groovy:9)
the script does not have any errors but when i assign the Issue to my id the group field not generating the value
Can you please suggest me how to achieve this
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The error log tells you that on line 9, there is an error with getCustomFieldValue - the most likely reason is that you have fed it nonsense for the custom field, so I'd then look at line 7 where you set the variable. Best guess - you don't have a custom field called "assignee", or you have two or more.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nic Brough -Adaptavist- Thanks for you response
Here i'm using on create and edit screens "Assignee" is system filed and "Assignment Group" is Group picker field that i created
I have modified again script still the logs shows an error
Logs:
2019-01-16 18:26:34,972 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2019-01-16 18:26:34,972 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896) at com.atlassian.jira.issue.Issue$getCustomFieldValue$5.call(Unknown Source) at Script995.run(Script995.groovy:9)
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, so you need to use the Assignee field, not the non-existent "assignee" custom field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI @Nic Brough -Adaptavist- Thanks for your response
Yes that's correct
I want to use "Assignee" Field which is already exist in jira
Here What i'm trying to do is I will Give all the User's name's and Related Group inn the script so when ever the Issue get Created / Updated if the Users that i mention in the script if they are in "Assignee" Field of the issue then the "Assignment Group" has to appear with that value automatic.
This is what i'm trying to do
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I know what you're trying to do. You need to use the Assignee from the issue, not a custom field that does not exist.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nic Brough -Adaptavist- Thanks for your response
Here I have achieved in one way On issue create transition i added an "Post-function custom script "
In the Script i mention the "group name" so here when ever the issue is creating while creating if the issue is assignee to user from the Given group then the group field will display the Group name on view screen.
its worked as expected
But I need to add in the script all groups to display when the users from those group got assigned to that issue its has to display the user belonged group name in that group field
while Creating the issue and Updating the issue
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
if (groupManager.isUserInGroup(issue.assignee?.name, 'Developer-jira1')) { // Check if the user in Group A
def cf = customFieldManager.getCustomFieldObjectByName("Assignment Group") // group Custom Field
def correctGroup = groupManager.getGroup("Developer-Jira1") // Get the Group we want to set the custom field to
List<Group> groupList = new ArrayList<Group>() // We need to make a list to add to the group to
groupList.add(correctGroup) // You have to pass a list to the GroupPicker custom field
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), groupList), changeHolder) // Update the issue
}
Can you please help me in script that adding the extra groups
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm a bit stuck - I think you are trying to do this:
>all groups to display when the users from those group got assigned to that issue its has to display the user belonged group name in that group field
But that does not make sense. Could you explain it for me?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nic Brough -Adaptavist- Thanks for your response
> I have resolved it I wrote a Script Listener Script in that I mention all groups so when ever the user assigned to any issue if that user belonged to one of those group it will display the user belonged group.
> If the User is in multiple groups in that case when ever the Script listener logs reads the group info it will take the 1st group name of that user who is in Multiple groups
Here I'm trying to add one more thing Nic could you please help How to get that
> When Ever the Group Field changes Assignee Filed has to set "Unasigned"
Here i'm trying to get the info when the Issue got updated i wantt to read which field has been updated in the Script Listener
Can you please tell how to achieve this
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
https://library.adaptavist.com/entity/update-the-value-of-a-custom-field-using-a-listener has some listener code that lets you read through what is contained in an event (including field changes)
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.
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.