Match the value of a custom field to all the issues in the particular project and then set the value of another custom field in all the issues.

anubhav priya January 9, 2014

My requirement is:
On create of an issue in JIRA, it should grab a particular value from the email address (say "domain_name" ), and based on that domain_name, search for all the issues that have the same domain_name. Then set the value of a custom field as fetched from the matched issues, in the created JIRA issue.

This is my code:

ComponentManager componentManager = ComponentManager.getInstance();
customFieldManager = componentManager.getCustomFieldManager();
IssueManager issueManager = ComponentAccessor.getIssueManager();
def public SupportPlan(MutableIssue issue)
{
    ComponentManager componentManager = ComponentManager.getInstance();
    customFieldManager = componentManager.getCustomFieldManager();
    IssueManager issueManager = ComponentAccessor.getIssueManager();
    def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
    User currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

    CustomField cfmail = customFieldManager.getCustomFieldObjectByName("Customer Email");
    String cfmailV=(String)issue.getCustomFieldValue(cfmail);

    //Fetch domain name value
    def dmain_name = cfmailV.substring(cfmailV.indexOf("@")+1, cfmailV.lastIndexOf("."));
    JqlClauseBuilder builder = JqlQueryBuilder.newClauseBuilder();
    Query query = builder.customField(cfmail.getIdAsLong()).like(cfmailV).buildQuery();
    SearchProvider searchProvider = ComponentAccessor.getComponentOfType(SearchProvider.class);
    SearchResults searchResults = searchProvider.search(query,currentUser,PagerFilter.getUnlimitedFilter());
   List<MutableIssue> issues = searchResults.issues.collect {issueManager.getIssueObject(it.id)}

    for (def allIssues : issues)
    {
        String cfAIemailv = (String)allIssues.getCustomFieldValue(cfmail);
        String aidmain_name = cfAIemailv.substring(cfAIemailv.indexOf("@")+1, cfAIemailv.lastIndexOf("."));

          if(dmain_name == aidmain_name)
        {
           CustomField cfSupport = customFieldManager.getCustomFieldObjectByName("Support Type");
           String cfSTypeV =(String)issue.getCustomFieldValue(cfSupport);
           allIssues.setCustomFieldValue(cfSupport,cfSTypeV);
        }

    }
}

SupportPlan(issue);

I am not able to set the value to the custom field named "Support Type"

Pls help.

1 answer

0 votes
JamieA
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.
January 10, 2014

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events