On the selection of dropdown value how to change the assignee

Najmul Khan June 19, 2014

I want to change the name of the assignee on the selection of the Region dropdown value.

How can I achieve this, Please share the code for the same.

2 answers

0 votes
Paresh Gandhi
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.
June 24, 2014

If you are doing this at issue creation and before submitting if you want to change value then I guess java script - before performing any event or issue update.

If you want to happen this on issue created, updated event then groovy script do where it will actually change the asignee and email notification will flot

e.g.

import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Logger
import static org.apache.log4j.Level.DEBUG
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.issue.index.IssueIndexManager

class invoketransition extends AbstractIssueEventListener {
        Logger log = Logger.getLogger(invoketransition.class)
        @Override
        void issueUpdated (IssueEvent event) {
                log.setLevel(org.apache.log4j.Level.DEBUG)
                def field = event.getChangeLog().getRelated('ChildChangeItem').any{ it.field.toString().equalsIgnoreCase("YourFieldName")}
                if (field){
                	def cfg = customFieldManager.getCustomFieldObjects(issue).find {it.name == "YourFieldName"}
                        def cfgvalue =(List<Group>)issue.getCustomFieldValue(cfg)
                        if (cfgvalue == "1")
                        	//set issue.assignee = "abc"
                        //else if and so on
                }
       }
}

Najmul Khan June 24, 2014

Hi Paresh,

Thanks for your help,

The code provided by you is not worked in my case I tried several time but nothing seems to be worked.

Could you please share some code that I can write in the Behaviour, So that while filling the field user can see the update what is going on.

Plesse do the needful

Regards

Najmul Khan June 30, 2014

Hi,

Could you help me to resolve the above issue.

Any updates on this issue

0 votes
Vijay Khacharia
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.
June 19, 2014
Najmul Khan June 23, 2014

Hi Vijay,

I want to change the name of Assignee on the selection of custom field value.

for eg:

If the custom field selected value is "1" then Assignee name should be "abc", If the custom field selected value is "2" then Assignee name should be "pqr", if the custom field selected value is "3" then Assignee name should be "xyz" and etc...

Is this possible to change the name of the Assignee on the selection of dropdown value?

Please do the needful.

Regards

Vijay Khacharia
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.
June 24, 2014

Hi Najmul,

I havent done this myself yet so cant say the articles I posted helps you directly. They are more specific requests and you have to modifiy accoding to your needs.

I can try it for you once I have time. I will get back if I get it to work.

Vijay

Najmul Khan June 24, 2014

Hi Vijay,

Many thanks for your support, Please let me know when you get any positive output.

Regards

Vijay Khacharia
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 1, 2014

Hi,

This is working for me

<script type="text/javascript">
  source = document.getElementById('customfield_13750');
  if (source) {
      target = document.getElementById('assignee');
      // Hide the target field if priority isn't critical
      source.onchange=function() {
          if (this.value == <selection option id>) {
                     target.value='assignee_user_name';
                  }
      }
  }
 </script>

You need to change the customfield ID and the assignee name. Also make sure the <selection_option_id> is the id of the option of the customfield and not the option itself. It is a 5 digit number normally.

Vijay

Najmul Khan July 2, 2014

Thanks Vijay,

I am using your code and working fine but the value is not going to be set into the Assignee field. I tried multiple time with the help of alert.

And found every line is executing properly upto the end. The target.value getting the value also but the value is not coming in the Assignee field on the UI.

Could you please help me to come out form this.

Vijay Khacharia
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 2, 2014

Hi Najmul,

You have to put the code in the description field of the customfield. Go to Administration -> Addons -> Custom Fields -> Find your customfield -> Edit and put the script in description of the field.

Here is the doc link.

https://confluence.atlassian.com/display/JIRA/Configuring+a+Custom+Field#ConfiguringaCustomField-editEditingacustomfield

This makes it global for all the projects that use the custom field. If you want to do specific to one project, you need to edit it in the field configuration scheme for that project. Doc link below.

https://confluence.atlassian.com/display/JIRA/Specifying+Field+Behavior#SpecifyingFieldBehavior-Editingafieldconfiguration

Vijay

Najmul Khan July 2, 2014

Yes Vijay I did in the same place, But I found the above issue. Could you please help me!

Suggest an answer

Log in or Sign up to answer