Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2017

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

0 votes
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2017

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. 

Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2017

Hi Joshua,

I really appreciate you reply.

I tried your code but its throwing NullPointerException.

Null.PNGIs that anything mistake in the code?

 

Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2017

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

 

Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2017

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) 

Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2017

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.

Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2017

Hi Joshua,

Thank you so much it worked.

 

Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2017

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

Just for knowledge.

Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 10, 2017

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
TAGS
AUG Leaders

Atlassian Community Events