Hi,
I have some values in components field almost 20+ values,
If components fields starts with ("Below The line") want to set current assignee to Developer(s) else Tester(s).
Example: Components having values 'Configurations', 'Enhancement', 'Below The line-Rule', 'Automation', 'Below The line-PDF'.
When user selects components as 'Below The line-PDF' value, the Developer(s) field get automatically filled with current assignee.
Any scripts?
Thanks
Hi Teju,
I think you could accomplish this fairly easy using a post-function script. For example, you could create a post-function on the Create step of the workflow that will set the custom field based on what the user has selected for components. The script would look something like this:
import com.atlassian.jira.component.ComponentAccessor; def customFieldManager = ComponentAccessor.getCustomFieldManager(); def devField = customFieldManager.getCustomFieldObjectByName('Developer(s)'); def testField = customFieldManager.getCustomFieldObjectByName('Testers(s)'); if (issue.componentObjects*.name.contains('Below The line')) { issue.setCustomFieldValue(devField, issue.assignee) } else { issue.setCustomFieldValue(testField, issue.assignee) }
If your components have "Below The line" or "Below The line-PDF", it will set the Developer(s) field to the assignee. If not, it will set the Tester(s) field to the assignee.
Hi Joshua,
I really appreciate you reply.
I tried your code but its throwing NullPointerException.
Is that anything mistake in the code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like I wrote 'Testers(s)' for the custom field name instead of 'Tester(s)' in my script. Have you tried changing that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah I changed that but I didnt work for me.
May be we need to get current assignee in that script and set it to Developer(s) or Tester(s)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Teju,
I went back and tested the script with my workflow. I forgot that you need to use the updateValue() method to actually affect change to the customFields. See updated script below.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.ModifiedValue def customFieldManager = ComponentAccessor.getCustomFieldManager() def devField = customFieldManager.getCustomFieldObjectByName('Developer(s)') def testField = customFieldManager.getCustomFieldObjectByName('Tester(s)') def assignee = issue.assignee.name def components = issue.componentObjects*.name as String def changeHolder = new DefaultIssueChangeHolder() if (components.contains('Below The line')) { devField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(devField), assignee), changeHolder); } else { testField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(testField), assignee), changeHolder); }
I tested it and it seems to work. See images:
Developer(s):
Tester(s):
You might want to actually require that the user enters an assignee/component if you don't already.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Joshua,
Thank you so much it worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One last thing how will i set Developer(s) value to Assignee?
Just for knowledge.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Teju,
In my script, I defined an assignee variable:
def assignee = issue.assignee.name
That will allow you to get the name of the assignee of the issue. There is a page on the Atlassian website that will tell you all of the methods that you can use on an issue. For instance, you use the issue.reporter method to the reporter or issue.key to get the key.
Once you've got the information and stored it in a variable, it's just a matter of using it. I used the updateValue method to set the Developer(s) field to the assignee variable that I defined earlier.
devField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(devField), assignee), changeHolder);
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.