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.

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

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...

507 views 3 18
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