Use a Post Function to Update the Priority Based on Multiple Custom Fields

Lesley_Groh April 7, 2020

Hi,

I have looked and looked and tried to find this answer on my own, but I am coming up empty.  Please help me!

I keep getting this error:  groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script386.

I took the Adaptavist script, "Update Priority Based on a Custom Field," from the online library and tried to make it work as I need it, but this error persists.

Problem I am trying to solve is:  I have 6 custom fields.  All of them need to have the value of "No" then set Priority = Level 1.  If ANY ONE of the custom fields = "Yes" then set Priority = Level 2.  So, I tried to change their script to this (I'm sorry, I tried to use the code block, but I can't get it to allow my text to be copied in).  It's just not working.  Any suggestions?

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.opensymphony.workflow.InvalidInputException;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.config.PriorityManager;
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption;

final String customFieldName = "1. Are you aware of any System issues that may have contributed to the problem?" || "2. Are you aware of any Communication issues that may have contributed to the problem?" || "3. Are you aware of any transition issues that may have contributed to the problem?" || "4. Are you aware of any Quality issues that may have contributed to the problem?" || "5. Was this problem not primarily related to the natural course of the request?" || "6. Is there anything else you would want us to know about this problem?"

CustomFieldManager cFieldManager = ComponentAccessor.getCustomFieldManager();
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)

def customFieldVal = issue.getCustomFieldValue(customField) as LazyLoadedOption

def priorities = ComponentAccessor.getComponent(PriorityManager).priorities

def highestPriority = priorities.findByName("Level 2")
def highPriority = priorities.findByName("Level 1")

switch (customFieldVal?.value) {
case "Yes":
issue.setPriorityId(highestPriority.id)
break
case "No":
issue.setPriorityId(highPriority.id)
break
}

 

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 13, 2020

You have used two different names for the "custom field manager" object.

When you've fixed that, I suspect you will find the switch fails because I suspect the fields are not string fields, and then the set value will fail because the priorties.findByName does not return an id.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events