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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

136 views 0 4
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