I've created a change request JSD project. It is used to terminate existing employees/contractors. When terminating an employee, I need to ensure that only HR staff can create such a request. Anyone can terminate a contractor.
I have a custom field called "Category" that has options a) Employee b) and Contractor. So if "Employee" is selected, I need some validator that ensures the issue create is a member of the HR Termination project role. I found a script online that I've modified, but it isn't quite working.
The following script throws the error no matter what option is selected, Employee or Contractor. So somehow this code isn't specifically checking to see what value was selected in my Category custom field.
Any help would be appreciated.
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.ProjectRole
import com.opensymphony.workflow.InvalidInputException
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction");
ComponentManager componentManager = ComponentManager.getInstance();
ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager;
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10201");
def cfCategory = (String)issue.getCustomFieldValue(customField);
ApplicationUser currentUser = ComponentAccessor.JiraAuthenticationContext.getLoggedInUser();
ProjectRole hrRole = projectRoleManager.getProjectRole("HR Termination");
ProjectRoleActors hr = projectRoleManager.getProjectRoleActors(hrRole, issue.getProjectObject());
Boolean isHR = hr.contains(currentUser);
if (!isHR) {
if (cfCategory == "Employee")
return false
}