Auto-Assign Issue using custom field

This code was written using a more complicated example pulling values from the new 'cascadeselect' custom field type - so it might not work, but it should get you very close.

...

Note: You (the developer) will want to modify this code to whatever package you are using to put your jira extensions in. Then compile it, jar it up, and put the jar in <jira install>/WEB-INF/lib directory

Then restart JIRA

To access this function from the JIRA workflow editor you would need to make it a plug-in or just modify the xml directly.

If you are compiling your extensions directly into JIRA then just change the package line below to:
package com.atlassian.jira.workflow.function.issue;

AssignIssueFromCustomField.java
package com.newisys.jira.workflow.function;

import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.FunctionProvider;

import org.apache.log4j.Category;
import org.ofbiz.core.entity.GenericValue;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;

/**
 *  Assign issue using value in custom field
 *
 *  Required Argument: name - contains the name of the custom field that contains value
 *
 *  Note: No validation on custom field contents is preformed
 */
public class AssignIssueFromCustomField implements FunctionProvider
{
    private static final Category log = Category.getInstance(AssignIssueFromCustomField.class);

    public void execute(Map transientVars, Map args, PropertySet ps)
    {
        // Get the name of the link type
        String customFieldName = (String) args.get("name");
        if (customFieldName == null) throw new IllegalArgumentException("Must specify a 'name' arg specifying name of the custom field");

        try
        {
            // get compoent from custom field
            GenericValue issue = (GenericValue) transientVars.get("issue");

            // get issue custom fields
            List customFields = ManagerFactory.getCustomFieldManager().getCustomFieldObjects()

            // This line doesn't work yet... :(
            //((CustomFieldManager)JiraUtils.loadComponent(CustomFieldManager.class)).getCustomFieldObjects(issue);

            // get custom field
            CustomField cf = null;
            Iterator cfit = customFields.iterator();
            while(cfit.hasNext())
            {
                cf = (CustomField ) cfit.next();
                if(cf.getName().equals(customFieldName))
                {
                    // ok, we have the custom field object now - get the value and set the issue assignee property
                    String customFieldValue = (String ) cf.getValue(issue);

                    //log.error("customFieldValue: " + customFieldValue);
                    issue.set("assignee", customFieldValue);

                    break;
                }
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return;
    }
}

Labels

workflow workflow Delete
plugin plugin Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jul 25, 2005

    Craig Blake says:

    This doesn't even compile. There is no ManagerFactory in the Jira sources that ...

    This doesn't even compile. There is no ManagerFactory in the Jira sources that I can find.

  2. Jul 26, 2005

    Anton Mazkovoi says:

    The full package name is: com.atlassian.jira.ManagerFactory It looks like the a...

    The full package name is:
    com.atlassian.jira.ManagerFactory

    It looks like the above code is missing an import statement?

  3. Apr 13, 2007

    nataliab says:

    Hello, I would need to use this extension! Is there any jar whit it? Thank...

    Hello,

    I would need to use this extension! Is there any jar whit it?

    Thanks in advanced,

  4. Aug 31, 2007

    siandallaway says:

    It would be SO GOOD if someone who knows the system could kick this into shape a...

    It would be SO GOOD if someone who knows the system could kick this into shape and offer it as a parameterized plugin.  As someone who has spend all day struggling to do just that (not knowing the system) I'd be hugely grateful.

    Unless anyone knows of a similar plugin already developed?  Or even something to cascade assignee changes from an issue to its subtasks in the same way that the Transition Subtasks plugin works?

    1. Feb 25, 2008

      Moisés Delgado says:

      Hi Sian, Did you have any answer about this? I'm interesting in a plug-in for t...

      Hi Sian, Did you have any answer about this?

      I'm interesting in a plug-in for this too.

      If you know something i will appreciate the information..

      Thanks! 

  5. Oct 30

    Martin Sweitzer says:

    Any chance someone with src code access can compile a .jar for this?

    Any chance someone with src code access can compile a .jar for this?