How to set Developer(s) and Tester(s) field automatically based upon Components fields postfunc?

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

1 answer

1 accepted

This widget could not be displayed.

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.

Null.PNGIs that anything mistake in the code?

 

Looks like I wrote 'Testers(s)' for the custom field name instead of 'Tester(s)' in my script. Have you tried changing that?

 

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) 

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

Screen Shot 2017-07-06 at 12.17.21 PM.png

Tester(s):

Screen Shot 2017-07-06 at 12.17.04 PM.png

You might want to actually require that the user enters an assignee/component if you don't already.

Hi Joshua,

Thank you so much it worked.

 

One last thing how will i set Developer(s) value to Assignee?

Just for knowledge.

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

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

531 views 3 19
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you